Hello. When I touch one object, all object (clones) is destroyed. How can i fix it ? Code (csharp): using UnityEngine; using System.Collections; public class DestroyObjectesEasy : MonoBehaviour { public static int myScore1 = 10; public static int Highscores=0; public static bool isDead=false; public AudioClip shootSound; public AudioSource source; public float volLowRange = .5f; public float volHighRange = 1.0f; public void awake() { source = GetComponent<AudioSource>(); } /* void OnMouseDown() { isDead = true; Destroy (this.gameObject); StartSinking (); }*/ void Update() { if (Input.touchCount > 0) { int i = 0; for (i = 0; i < Input.touchCount; i++) { Destroy(this.gameObject); } //Do something with the touches isDead = true; //Destroy (this.gameObject); Scoring (); //if (Input.GetButtonDown ("Fire1")) { float vol = Random.Range (volLowRange, volHighRange); if (isDead == true) source.PlayOneShot (shootSound); isDead = false; } } public void Scoring () { ScoreManagerEasy.score1 += myScore1; } }
I assume that code is on each of the clones? it basically reads "if there is a touch (anywhere) destroy this gameobject" you want it to read "if there is a touch over this game object, destroy this gameobject" (or something similar depending on how you want your game to work )
you are basically destroying game object on touch itself. So this script attached to every gameobject destroys.
What I must to do, that after double-tap in two objects Both were destroyed? Code (csharp): if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position); RaycastHit hit; int i = 0; for (i = 0; i < Input.touchCount; i++){ if ( Physics.Raycast(ray, out hit) && GameObject.FindGameObjectWithTag("RollerBallEasy")) { Destroy(hit.transform.gameObject); isDeadEasy = true; } } Problem is resolved : Code (csharp): void Update() { RaycastHit hit; for (var i = 0; i < Input.touchCount; ++i) { Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(i).position); if (Input.GetTouch(i).phase == TouchPhase.Began) { } } }