- Home /
problem with touch android
hello I have a problem (perhaps trivial) with the touch. The objective of the game is to click on the blue balls for points. These balls are constantly changing color so if I click that are colored red, yellow, green should take points. I tested the project is for PC for Android. For PC works great for Android, not much. Sometimes when I click on the blue balls it takes away points instead of accumulate. Here's the script: Touch;
function Update ()
{
//loop through all registered touches
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (
Input.GetTouch(i).position
);
if (Physics.Raycast (ray, hit, 10000))
{
Destroy(hit.transform.gameObject);
gameObject.Find("Sphere(Clone)").SendMessage("Tablet");
}
}
}
}
Color random:
#pragma strict
var texBall : Texture[] = new Texture [5];
var randomtex : int;
function Start(){
textureRandom(); //esegui la funzione textureRandom
collider.enabled = true;
}
function update(){
}
function textureRandom(){
while(true){ //finchè è vero esegui il ciclo
yield WaitForSeconds(1); //aspetto 1 secondo e cambio colore alla mesh
// variabile randomColor
randomtex = Random.Range(0, texBall.length); //random della variabile cambiaColore
renderer.material.mainTexture= texBall[randomtex]; // lo assegno alla variabile randomColor
if( randomtex == 0) { //Se rossa
collider.enabled = true; //attivo collider
//print("collider attivo");
}
else{
collider.enabled = true; //altrimenti disattivo
}
}
}
function Tablet(){ //se collider attivo
if(randomtex == 3){ //rosso
Destroy(gameObject);
gameObject.Find("Main Camera").SendMessage("aggiorna");
gameObject.Find("Main Camera").SendMessage("sound");
}
else{
gameObject.Find("Main Camera").SendMessage("decrementa");
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613090114im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
script is not working Using raycast show PopUp on click 0 Answers
GUI label on raycast? 0 Answers
3D Text is blocking mouse click on object behind 1 Answer
problem with raycasting and functions 1 Answer
Problem with raycast 0 Answers