- Home /
Question by
RaulBernardo · Dec 06, 2016 at 06:55 AM ·
script.
What's wrong?
Unity is indicating this error when starting the game:
ArgumentException: Index out of bounds. ControllerTree2.Update () (at Assets/Scripts/ControllerTree2.cs:14)
using UnityEngine; using System.Collections;
public class ControllerTree2 : MonoBehaviour { Animator TrunkAnimator; // Use this for initialization void Start () { TrunkAnimator = GetComponent (); }
// Update is called once per frame
void Update () {
Touch touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Began){
if(touch.position.x > Screen.width/2){
//left
TrunkAnimator.SetBool ("Attack2", true);
TrunkAnimator.SetBool ("Stop2", false);
} else {
TrunkAnimator.SetBool ("Attack2", false);
TrunkAnimator.SetBool ("Stop2", true);
}
}
}
}
Comment
Answer by tanoshimi · Dec 06, 2016 at 07:00 AM
If you're not touching the screen, Input.GetTouch(0);
will fail because there isn't a touch to get. You should check the lengt of Input.touches first.