- Home /
Question by
kumar.annamraju · Jan 24, 2014 at 01:46 PM ·
gameobjectaddcomponent
Add instantiated class to gameobject
I am creating 10 cubes over runtime and I need to add an object which is not inherited from Mono Behaviour. I have looked at Add Component but that needs a class to be inherited Mono Behaviour. So is there any other option.
So here is the scenario:
I am creating a cube at random positions and I need to save that initial position attached to the Cube gameObject so I can access it as and when needed. So what is the possible option.
Comment
Answer by njpatter · Jan 24, 2014 at 02:11 PM
Looking for a vector3 to be attached to a gameObject?
using UnityEngine;
using System.Collections;
public class PositionGrabber : MonoBehaviour {
public Vector3 initialPosition;
void Start() {
initialPosition = transform.position;
}
}
Your answer
