Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

GUITexture in Unity 5

$
0
0
Hi, I have been following this tutorial to make a 2D mobile game. However, I find a difficulty in scripting for the virtual buttons. The "Character" won't move when I touch the virtual buttons. There is also the ArgumentException:Index is out of bounds error message. I think the error is in the GUITexture part, but I'm not sure how to fix it. Can anyone help me solve this problem? Thanks! Here's the script for TouchManager.cs using UnityEngine; using System.Collections; public class TouchManager : MonoBehaviour { public bool guiTouch = false; public GUITexture texture; public void TouchInput(){ if (Input.touchCount > 0) { guiTouch = true; if (texture.HitTest (Input.GetTouch (0).position)) { switch (Input.GetTouch (0).phase) { case TouchPhase.Began: SendMessage ("OnFirstTouchBegan"); SendMessage ("OnFirstTouch"); break; case TouchPhase.Moved: SendMessage ("OnFirstTouchMoved"); SendMessage ("OnFirstTouch"); break; case TouchPhase.Stationary: SendMessage ("OnFirstTouchStayed"); SendMessage ("OnFirstTouch"); break; case TouchPhase.Ended: SendMessage ("OnFirstTouchEnded"); guiTouch = false; break; } } } } } and here's the script for MovementControl.cs using UnityEngine; using System.Collections; public class MovementControl : TouchManager { public bool moveRight = false; public GameObject player = null; public float speed = 25.0f; void Update () { TouchInput (); } void OnFirstTouch(){ if (moveRight) { transform.Translate (Vector2.right*speed*Time.deltaTime); } else if(!moveRight){ transform.Translate(-Vector2.right*speed*Time.deltaTime); } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>