Quantcast
Channel: Questions in topic: "empty gameobject"
Viewing all articles
Browse latest Browse all 4

Using polymorphysm with objects in Unity.

$
0
0
Hey! I created abstract class named "PowerUp" and few child classes like: BonusHeath, DoubleDamage, AmmoPack. Now I have objects in Editor with script to rotate power up's: [...] public PowerUp objectType; void Update () { transform.Rotate (new Vector3(0f, 0f, Time.deltaTime * rotationSpeed)); } void OnTriggerEnter(Collider collider){ if (collider.gameObject.tag == "Player") { //this.GameObject.FindComponent().SendMessage ("OnPickup", 30,SendMessageOptions.DontRequireReceiver); //i dont' want to use this myObject.OnPickup(); ///i want to use this Destroy(this.gameObject); } [...] And I want to use polymorphysm (by using method OnPickup() which is implemented in every PowerUp class by overriding). How I can implement it good? I can't use child script in parent's place. I really need to create an empty object with component and call him to call OnPickup() ?

Viewing all articles
Browse latest Browse all 4

Trending Articles



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