- Home /
Custom transform and gameObject
Hello, today I am here with a pretty weird question. So you know how you can cast gameObjects and transforms? Here are some examples:
public GameObject Player;
public Transform Player2'
void Update () {
Player.transform.Translate(Vector3.forward * 5);
Player2.gameObject.SetActive(false);
}
So I basically made my own "Object" class called "Entity". How can I make it so that if I do
public Entity Player;
It will show up in the inspector and I can drag in GameObjects or Transforms into that field. And also so I can cast it somehow using the "entity" (like "gameObject" or "transform") like this:
transform.entity.CustomEntityMethod();
Thanks!
Answer by hulahoolgames · Jan 08, 2016 at 01:28 AM
You will have to add the [Serializable] property to the class. Look here for examples. The properties of the class will show up in the inspector only if they can be serialized by unity. Hope this helps!
Not really. How do I make an "entity" keyword. And how can I make Unity know that entity is another type of in-game object that you can drag any object into the field in the inspector.
For example:
public Transform Player;
Player.entity.CustomEntity$$anonymous$$ethod();
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to keep a Gameobject in the same position after a transform.Rotate? 2 Answers
Shear transformation using GameObject transformations 2 Answers
How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers
Transforming a GameObject with an unattached script 1 Answer