Összes téma > Steam fórumok > Off Topic > Téma részletei
HELP C# (mathf.clamp)
Hi guys someone who knows C# can help me with this code? mathf.clamp dont work but the movement of the player work... im using unity engine

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class jugador : MonoBehaviour {

public float speed = 1f;
public float minX = -10f;
public float maxX = 10f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

if (Input.GetKey(KeyCode.A))
transform.position -= new Vector3(Mathf.Clamp(speed * Time.deltaTime, minX, maxX), 0f, 0f);

if (Input.GetKey(KeyCode.D))
transform.position += new Vector3(Mathf.Clamp(speed * Time.deltaTime, minX, maxX), 0f, 0f);


}
}
< >
16/6 megjegyzés mutatása
You are clamping the movement not thr position

This should fix it for first one

transform.position = new Vector3(Mathf.Clamp(transform.position.x*(speed * Time.deltaTime), minX, maxX), transform.position.y, transform.position.z);
tks for the answer :D, now the player dont move :S i change the mathf.clamp

if (Input.GetKey(KeyCode.A))
transform.position -= new Vector3(Mathf.Clamp(transform.position.x * (speed * Time.deltaTime), minX, maxX), 0f, 0f);

if (Input.GetKey(KeyCode.D))
transform.position += new Vector3(Mathf.Clamp(transform.position.x * (speed * Time.deltaTime), minX, maxX), 0f, 0f);
EDIT: sry bout that here is the fixed


transform.position = new Vector3(Mathf.Clamp(transform.position.x+(speed * Time.deltaTime), minX, maxX), transform.position.y, transform.position.z);
Legutóbb szerkesztette: Hannah Nelson!; 2017. okt. 9., 14:12
i try with solution but didnt work :( the player dont move
MayorCasey-twitch.tv/viduskate eredeti hozzászólása:
i try with solution but didnt work :( the player dont move
The second one?

Welp sorry not at my pc right now so cant do more to help

Keep trying tho

Good luck my friend
Legutóbb szerkesztette: Hannah Nelson!; 2017. okt. 9., 14:31
bro ttks for the help :D im trying to change the code, maybe i find who to do it xd
< >
16/6 megjegyzés mutatása
Laponként: 1530 50

Összes téma > Steam fórumok > Off Topic > Téma részletei
Közzétéve: 2017. okt. 9., 13:43
Hozzászólások: 6