Wszystkie dyskusje > Fora Steam > Off Topic > Szczegóły wątku
Mayor_Casey/TTV 9 października 2017 o 13:43
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);


}
}
< >
Wyświetlanie 1-6 z 6 komentarzy
Hannah Nelson! 9 października 2017 o 13:58 
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);
Mayor_Casey/TTV 9 października 2017 o 14:05 
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);
Hannah Nelson! 9 października 2017 o 14:08 
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);
Ostatnio edytowany przez: Hannah Nelson!; 9 października 2017 o 14:12
Mayor_Casey/TTV 9 października 2017 o 14:29 
i try with solution but didnt work :( the player dont move
Hannah Nelson! 9 października 2017 o 14:31 
Początkowo opublikowane przez MayorCasey-twitch.tv/viduskate:
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
Ostatnio edytowany przez: Hannah Nelson!; 9 października 2017 o 14:31
Mayor_Casey/TTV 9 października 2017 o 14:32 
bro ttks for the help :D im trying to change the code, maybe i find who to do it xd
< >
Wyświetlanie 1-6 z 6 komentarzy
Na stronę: 1530 50

Wszystkie dyskusje > Fora Steam > Off Topic > Szczegóły wątku
Data napisania: 9 października 2017 o 13:43
Posty: 6