This is my first time doing this so bare with me here. I am using Unity GUITexture and I want to detect touch only on the GUI Texture. I checked with the Penelope tutorial to try this out. I get an " Index Out of bounds" error and to the best of my knowledge this is not too far from the Penelope Touch control for the jump button. I also tried declaring it at the top too.
They have: var touch : Touch = Input.GetTouch(0);
var gunShell : Rigidbody;
private var bulletClone : Rigidbody ;
var machineGunFireButton: GUITexture;
var MachineGunFireSound : AudioClip;
private var touch : Touch;
var speed = 75;
var reloadTimer = 0.3;
private var reloadTime = 0.0;
private var nextFire : float = 0.0;
function Update ()
{
TurretFire ();
}
function TurretFire ()
{
touch =Input.GetTouch(0); //THIS LINE - UNITYEXCEPTION INDEX OUT OF BOUNDS
//if the texture is pressed at the texture location
if (machineGunFireButton.HitTest(touch.position) Time.time > nextFire)
{
nextFire = Time.time + reloadTimer;
bulletClone = Instantiate(gunShell, transform.position, transform.rotation);
bulletClone.velocity = transform.forward * speed ;//* -1;
if (nextFire)
{
AudioSource.PlayClipAtPoint(MachineGunFireSound, transform.position);
yield WaitForSeconds(audio.clip.length);
}
}
}