Hi!
I don’t know how to fix this errors:
- ArgumentException: Index out of bounds.
TouchManager.TouchInput (UnityEngine.GUITexture texture) (at Assets/_scripts/TouchManager.cs:8)
ButtonMovement.Update () (at Assets/_scripts/ButtonMovement.cs:26) - ArgumentException: Index out of bounds.
TouchManager.TouchInput (UnityEngine.GUITexture texture) (at Assets/_scripts/TouchManager.cs:33)
ButtonMovement.Update () (at Assets/_scripts/ButtonMovement.cs:26)
Here are the scripts:
TouchManager:
using UnityEngine;
using System.Collections;
public class TouchManager : MonoBehaviour{
public static bool guiTouch = false;
public void TouchInput (GUITexture texture){
if (texture.HitTest(Input.GetTouch(0).position)){
switch (Input.GetTouch(0).phase){
case TouchPhase.Began:
SendMessage("OnFirstTouchBegan");
SendMessage("OnFirstTouch");
guiTouch = true;
break;
case TouchPhase.Stationary:
SendMessage("OnFirstTouchStayed");
SendMessage("OnFirstTouch");
break;
case TouchPhase.Moved:
SendMessage("OnFirstTouchMoved");
SendMessage("OnFirstTouch");
break;
case TouchPhase.Ended:
SendMessage("OnFirstTouchEnded");
guiTouch = false;
break;
}
}
if (texture.HitTest(Input.GetTouch(1).position)){
switch (Input.GetTouch(1).phase){
case TouchPhase.Began:
SendMessage("OnSecoundTouchBegan");
SendMessage("OnSecoundTouch");
break;
case TouchPhase.Stationary:
SendMessage("OnSecoundTouchStayed");
SendMessage("OnSecoundTouch");
break;
case TouchPhase.Moved:
SendMessage("OnSecoundTouchMoved");
SendMessage("OnSecoundTouch");
break;
case TouchPhase.Ended:
SendMessage("OnSecoundTouchEnded");
break;
}
}
}
}
ButtonMovement:
using UnityEngine;
using System.Collections;
public class ButtonMovement : TouchManager {
public enum type {LeftButton, RightButton, JumpButton};
public type buttonType;
public GameObject playerObject = null;
public GUITexture buttonTexture = null;
Rigidbody2D playerRigidbody = null;
public float jumpHeight = 0.0f;
public float moveSpeed = 0.0f;
private Animator anim;
GroundChecker check;
void Start () {
playerRigidbody = playerObject.GetComponent<Rigidbody2D>();
check = playerObject.GetComponent<GroundChecker>();
anim = playerObject.GetComponent<Animator> ();
}
void FixedUpdate (){
anim.SetBool ("Grounded", check.grounded);
}
void Update () {
TouchInput (buttonTexture);
}
void OnFirstTouchBegan (){
if(check.grounded == true){
switch (buttonType) {
case type.JumpButton:
playerRigidbody.AddForce(Vector2.up * jumpHeight, ForceMode2D.Impulse);
break;
}
}
}
void OnSecoundtTouchBegan (){
if(check.grounded == true){
switch (buttonType) {
case type.JumpButton:
playerRigidbody.AddForce(Vector2.up * jumpHeight, ForceMode2D.Impulse);
break;
}
}
}
void OnFirstTouch (){
switch (buttonType) {
case type.LeftButton:
playerObject.transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
break;
case type.RightButton:
playerObject.transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
break;
}
}
void OnSecoundTouch (){
switch (buttonType) {
case type.LeftButton:
playerObject.transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
break;
case type.RightButton:
playerObject.transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
break;
}
}
}