Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Input problem

Discussion in 'Scripting' started by naapperas, Mar 25, 2016.

  1. naapperas

    naapperas

    Joined:
    Mar 25, 2016
    Posts:
    3
    Well, I made exactly everything the tutorial "Roll a Ball" showed and, surprise, it doesn't work. Well, can anyone tell me what's going wrong:
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerControler : MonoBehaviour {

    public float speed;
    public Text Counttext;
    public Text winText;​

    private Rigidbody rb;
    private int count;
    private float moveHorizontal;
    private float moveVertical;​

    void Start ()
    {
    rb = GetComponent<Rigidbody>();

    count = 0;
    SetCountText();
    winText.text = "";​
    }​

    void Fixedupdate ()
    {
    moveHorizontal = Input.GetAxis ("Horizontal");
    moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.AddForce (movement * speed);​

    }

    void OnTriggerEnter(Collider other)
    {

    if (other.gameObject.CompareTag("Pick Up"))
    {
    other.gameObject.SetActive(false);
    count++;
    SetCountText();​
    }​

    }

    void SetCountText()
    {
    Counttext.text = "Points: " + count.ToString();
    if (count >= 17)
    {
    winText.text = "You win!!!";​
    }​
    }​
    }
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Please use code tags.

    You have a typo in 'FixedUpdate'.
     
  3. naapperas

    naapperas

    Joined:
    Mar 25, 2016
    Posts:
    3
    Thanks, i've checked that and other things and now it works. Thanks a lot for making me not loose total hope on myself and on the little I know on Unity.