public void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { if (!player || !player.activeInHierarchy) { player = GameObject.FindGameObjectWithTag("Player"); if (!player) { return; } playerHealth = player.GetComponent <PlayerHealthScriptFinal>(); } print("healed"); if (playerHealth.currentHealth < playerHealth.startingHealth) { playerHealth.TakeDamage(-25); } Destroy(this.gameObject); } }
void Awake() { player = GameObject.FindGameObjectWithTag("Player"); if (player) { playerHealth = player.GetComponent <PlayerHealthScriptFinal>(); } }
// Update is called once per frame void Spawn() { currLength = spawnPoints.Count; if (!playerHealth.gameObject.activeInHierarchy) { if (GameObject.FindGameObjectWithTag("Player")) { playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealthScriptFinal>(); } else { return; } } if (playerHealth.currentHealth <= 0f) { return; } int spawnPointIndex = Random.Range(0, currLength); //while (!spawnPoints[spawnPointIndex].gameObject.activeInHierarchy && currLength > 0) //{ // for (int i = spawnPointIndex; i + 1 < currLength; ++i) // { // spawnPoints[i] = spawnPoints[i + 1]; // } // --currLength; // spawnPointIndex = Random.Range(0, currLength); //} if (currLength > 0 && spawnPoints[spawnPointIndex].gameObject.activeInHierarchy) { //Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation); //GameObject obj = ObjectPoolScript.current.GetPooledObject(); GameObject obj = GetPoolObject(); obj.transform.position = spawnPoints[spawnPointIndex].position; obj.transform.rotation = spawnPoints[spawnPointIndex].rotation; obj.transform.SetParent(transform); obj.SetActive(true); //print(obj); //print(obj.activeSelf); //print(obj.activeInHierarchy); //print(obj.transform.parent); //print(obj.transform.parent); } }
void Update() { if (!player || !player.activeInHierarchy) { playerInRange = false; player = GameObject.FindGameObjectWithTag("Player"); if (player) { playerHealth = player.GetComponent <PlayerHealthScriptFinal>(); } } timer += Time.deltaTime; if (player && timer >= timeBetweenAttacks && playerInRange) { Attack(); } }