Quantcast
Channel: Questions in topic: "ads"
Viewing all articles
Browse latest Browse all 1416

multiple objects with same script, how to destroy one of them ?

$
0
0
this is the idea: there are many cubes with same script , this script destroys player and makes it respawn. i want to ask user to keep going if they watch a rewarded video so i made a panel and added button than wrote some code. problem is there are at least 90 cubes with same script so i cant really destroy the one player touched. these are my codes. enemy script on cubes: public class Carpisma : MonoBehaviour { public GameObject patlama; public GameObject PlayerDestroy; public GameObject uiw; private float t; public int scene; [SerializeField] private Transform player; [SerializeField] private Transform respawnPoint; public void ModeSelect() { StartCoroutine("Wait"); } private void Start() { t = Time.time + 2; } void OnCollisionEnter(Collision obj) { Debug.Log(Time.time); if (UnityEngine.Advertisements.Advertisement.IsReady() && Time.time>t) { t = Time.time + 2f; Time.timeScale = 0f; uiw.SetActive(!uiw.activeSelf); } else { Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation); GameObject.Find("Sphere").SendMessage("Finish2"); GameObject.Destroy(PlayerDestroy); Invoke("WaitingFunction", 1); } } public void Watchit() { UnityEngine.Advertisements.Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult }); } public void HandleAdResult(ShowResult result) { switch (result) { case ShowResult.Finished: Time.timeScale = 1f; GameObject.Destroy(gameObject); Debug.Log("bu itttt"); break; case ShowResult.Skipped: Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation); GameObject.Find("Sphere").SendMessage("Finish2"); GameObject.Destroy(PlayerDestroy); Invoke("WaitingFunction", 1); break; case ShowResult.Failed: Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation); GameObject.Find("Sphere").SendMessage("Finish2"); GameObject.Destroy(PlayerDestroy); Invoke("WaitingFunction", 1); break; } } void WaitingFunction() { SceneManager.LoadScene(scene); } public void again() { Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation); GameObject.Find("Sphere").SendMessage("Finish2"); GameObject.Destroy(PlayerDestroy); Invoke("WaitingFunction", 1); } } button script: ublic void Watchit() { Carpisma usit = FindObjectOfType(); usit.Watchit(); ui.SetActive(!ui.activeSelf); } this is the last thing that i need to fix to able to publish it right after fixing this. please share your knowledge. I've been asking for this since yesterday :)

Viewing all articles
Browse latest Browse all 1416

Trending Articles



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