- Home /
Different touches on screen
Hi guys! I have a sphere that rolls on planes that are created and colored randomly. I want that if the player touch the screen when the ball is rolling on the plane that has got its same color, the game goes on; but I want also that if the player touch the screen when the ball isn't rolling on the plane of the same color or if the player forget to touch the screen when the sphere is rolling on a plane that has its same color the game stop. How can I do?
This is the script that I attached on my sphere and it works perfectly : when the player touch the screen in the correct moment (when the ball is rolling on the correct plane) the game goes on and the counter increases. But I want to write also the other functions in this script.
#pragma strict
var sphere : GameObject;
var colors = [Color.red, Color.green, Color.blue, Color.yellow, Color.white];
function Update() {
var hit : RaycastHit;
if (Input.touchCount > 0) {
if (Physics.Raycast(transform.position, Vector3.down, hit)) {
Debug.Log(hit.collider.name +", " + hit.collider.tag);
var rend = hit.collider.renderer;
if (rend != null) {
if (rend.material.color == renderer.material.color) {
Debug.Log("Found a match");
Scorecounter.Counter ++;
sphere.renderer.material.color = colors[Random.Range(0, colors.Length)];
}
}
}
}
}
Answer by blenderblender · Sep 29, 2014 at 12:10 PM
void Update () { Touch myTouch = Input.GetTouch(0);
Touch[] myTouches = Input.touches;
for(int i = 0; i < Input.touchCount; i++)
{
//Do something
}
}
Yes, I know how to get touch input, but the thing that I want to know is another..