- Home /
How to assign one script on different gameobject of 1 prefab and make them run one by one
Hey guys, I need help. I have a prefab of door for all levels of my puzzle game. I want to execute the open door movement on each single one of them, not at the same time, but only when the player solves the puzzle of one level, the door would open. Down below is my script for opening the door, which I attached on my door Prefab.
public class DoorMove : MonoBehaviour
{
public Transform target;
private float t = 0.01f;
[SerializeField]
public bool _canMoveDoor;
public void Start()
{
//_canMoveDoor = true;
}
public void FixedUpdate()
{
StartCoroutine(Set());
}
public IEnumerator Set()
{
if (_canMoveDoor)
{
Coroutine b = StartCoroutine(Move());
yield return new WaitForSeconds(1.1f);
_canMoveDoor = false;
StopCoroutine(b);
yield return null;
}
}
public IEnumerator Move()
{
yield return new WaitForSeconds(1f);
Vector3 a = transform.position;
Vector3 b = target.position;
transform.position = Vector3.Lerp(a, b, t);
yield return null;
}
}
As you can see, I can control this script through the bool _canMoveDoor. Now, how do I give each single door an identity, so that I can execute this script only for the door that I want to open? Do I have to attach a int variable in this script like: _doorNumber?
Your answer
Follow this Question
Related Questions
MeshCombineUtility problem after upgrade to Unity 5? 2 Answers
Scripting error, no definition or an extension method. 1 Answer
Using AirBrakes on mobile device with Standard Assets AircraftController 0 Answers
How to detect an object which be in FOV of certain camera ? 1 Answer
Referencing a non static variable from another script C# Unity 1 Answer