Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Clones not using animator and enabling scripts?

$
0
0
I'm trying to make my enemy freeze when it gets in contact with an ice projectile. Everything works no errors except the animator doesn't play the animations and the script doesn't get enabled / disabled. I've tried script = GetComponent(); and anim = gameObject.GetComponent(); too for that section. And for the set active ive tried script.enabled script.setactive ect ect. None of it works. I think this might have to do with the get component but IDK. These are on instantiated prefabs btw. using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyHealth : MonoBehaviour { public float health; public float freezeTime; public Animator anim; public Enemy script; // Start is called before the first frame update IEnumerator Wait(){ yield return new WaitForSeconds (freezeTime); Debug.Log("waiting over"); } void Start() { anim = gameObject.GetComponent(); script = gameObject.GetComponent(); } // Update is called once per frame void Update() { if(health <= 0){ Dead(); } } void OnTriggerEnter2D(Collider2D other){ if(other.CompareTag("Harmful")){ Destroy(other.gameObject); TakeDamage(); } if(other.CompareTag("Freezing")){ anim.SetBool("IsFrozen", true); Destroy(other.gameObject); gameObject.GetComponent().enabled = false; TakeDamage(); Debug.Log("waiting started"); StartCoroutine(Wait()); anim.SetBool("IsFrozen", false); gameObject.GetComponent().enabled = true; } } void TakeDamage(){ health -= 1f; } void Dead(){ Destroy(gameObject); } }

Viewing all articles
Browse latest Browse all 508

Trending Articles