Answer the question
In order to leave comments, you need to log in
The script does not work, what's the problem?
I have a script, this script is responsible for the player's walking. There was a problem, the script partially does not work. When touched, the script should display the text and move the player, but it only displays the text. Here is the script itself:
using UnityEngine;
using UnityEngine.UI;
public class Walk : MonoBehaviour
{
private Animator player;
public float speddZ;
private Rigidbody rb;
public Finich fenich;
private float deltaPosX;
public Text text;
void Start()
{
player = gameObject.GetComponent<Animator>();
rb = gameObject.GetComponent<Rigidbody>();
}
void Update()
{
if (fenich.win == false)
{
if (Input.touchCount == 1)
{
text.text = "Touch";
deltaPosX = Input.GetTouch(1).deltaPosition.x;
rb.velocity = new Vector3(-deltaPosX * Time.deltaTime * 100, 0, speddZ * Time.deltaTime);
player.Play("Walking");
}
else
{
rb.velocity = new Vector3(0, 0, speddZ * Time.deltaTime);
player.Play("Walking");
} }
}
}
Answer the question
In order to leave comments, you need to log in
You have these lines in your code:
rb.velocity = new Vector2(-deltaPosX * Time.deltaTime * 100, 0);
rb.velocity = new Vector3(0, 0, speddZ * Time.deltaTime);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question