- Home /
Inheritance and Script References c#
Hi, I want to know how I would structure the following example.
I have an "Actor" script which inherits from mono behavior. I then have a "Player" script that inherits from Actor and an "Enemy" script that also inherits from actor.
If I add the player script onto my player game object does this create an instance of the player class? If so how can I get a hold of a reference to that object instance. I need to be able to have a variable in the Player class that is a reference to the targeted enemy. So that information from the enemy can be passed to the user interface and/or other functions. However when I try the following:
Enemy target;
void start()
{
target = GameObject.Find("Enemy").GetComponent(Enemy);
}
Surely this gets the script component (Enemy) of the game object "Enemy"?
I currently have a game object with my player script attached and an empty game object called "Enemy" with the Enemy script attached.
Answer by dfghdh · Dec 04, 2012 at 07:32 PM
Bump - When I create a class hierarchy does the base class have to extend mono develop? Or can I just create an instance of one of its derived classes in a script that does inherit from mono develop?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
I need help with a script(brauche hilfe mit einen Script) 0 Answers
animation.Play (MissingComponentException: There is no 'Animation' attached to.. 2 Answers
Crash the entire game 3 Answers
Distribute terrain in zones 3 Answers