I'm wondering if there is a way to have an Object when duplicated in the editor assign a GameObject variable to the newly duplicated version of itself. Is there an option in Unity or do I have to code it out.
So I would like it to follow these steps:
- So I would have the old GameObject with the variable named "nextStop" with nothing assigned to it.
- Then I duplicate said object and the older object's variable is assigned to the newly duplicated object.
- Done.
I'm doing this for a rail editor to make it easier to create new rails to follow.
I would like not to have to assign to each and every Object it will make things so much easier to explain for others to use. "Just duplicate these objects."
And in case you need it and Unity doesn't already have an option built in here's my code for the track.
using UnityEngine;
using System.Collections;
public class Rails : MonoBehaviour {
public GameObject nextStop;
LineRenderer myLine;
public bool endLevel = false;
public Train myShip;
void OnDrawGizmos()
{
if (nextStop) {
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, nextStop.transform.position);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "train")
{
if (nextStop)
myShip.track = nextStop;
if (endLevel)
{
// Load the next level
}
}
}
}
Oh yeah I should mention I have little experience modifying code to do things in the editor.