Hello everyone,
I have an Empty game object with a script attached that spawns my “coins”
I also have a simple coll detection script attached to my player body that detects when the coin is hit and the coin is set to not active.
That part seems to work fine.
I would now like my coll script to tell the Spawner Script that the coin “isDead” so that the script knows to respawn a new coin in the same spot after an elapsed set of time.
I will post both codes here. Keep in mind I haven’t put in the time delay for respawning as I’m not concerned with that part at the moment. I’m trying to get this code right first.
other.gameObject.transform.parent.GetComponent ("MySpawner").isDead = true;
<<<-- this line gives me error
My bool “isDead” is that supposed to be public of private?
I also don’t understand when you need to instansiate as GameObject and when you don’t need to do that.
Thanks for reading!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColDetection : MonoBehaviour {
private int score; //How much Pepecash you have
// Use this for initialization
void Start () {
score = 0;
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "PepeCash")
{
other.gameObject.SetActive (false);
score = score + 1;
Debug.Log ("Score =" + score);
other.gameObject.transform.parent.GetComponent ("MySpawner").isDead = true;
}
}
}
And other script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MySpawner : MonoBehaviour {
public GameObject spawnAsset;
private GameObject newSpawnAsset;
public bool isDead;
// Use this for initialization
void Start () {
isDead = false;
newSpawnAsset = Instantiate(spawnAsset, transform.position, transform.rotation);
}
void Respawn ()
{
if (isDead == true) {
newSpawnAsset = Instantiate (spawnAsset, transform.position, transform.rotation);
isDead = false;
}
}
}