Hey dears , i have multiple gameObject with the same script all alright but when i execute the script take the last instance variables , i want it to take on every gameobject the variable that i assigne it on it please help :
Edit : I’m so sorry for my bad English , yeah the problem was that I want to pair two doors so the player enter in one door and exit from the other (the other door is a transform that I have to initialize it from the inspector for every door) so the script work just for the last door but If I enter in the first one it take the transform of the last instance of the door
using UnityEngine;
using System.Collections;
public class NewDoorScript : MonoBehaviour
{
bool touchDoor;
GameObject player;
public Transform otherDoor; // this is the variable that change on every
gameobject
public bool lastLevel;
public string levelName;
Animator anim;
private static bool openTheDoor;
public static bool enter;
static bool goBack;
// Use this for initialization
void Start ()
{
touchDoor = false;
openTheDoor = false;
this.anim = GetComponent<Animator>();
goBack = true;
player = GameObject.FindGameObjectWithTag("Player");
otherDoor = this.GetComponent<NewDoorScript>().otherDoor;
}
public void enterTheDoor ( bool enterF )
{
enter = enterF;
Debug.Log("hello");
}
public static void openDoorFun ()
{
openTheDoor = true;
}
// Update is called once per frame
void Update ()
{
if (/*enter Input.GetKey("space")*/openTheDoor && touchDoor)
{
if (lastLevel)
{
Application.LoadLevel(levelName);
enter = false;
}
else
{
this.anim.SetBool("openDoor", true);
}
}
else
{
// openTheDoor = false;
}
}
public void gbf ()
{
player.transform.position = new Vector3(otherDoor.position.x, otherDoor.position.y, -1); // here it take the last gameobject's otherDoor variable not the current
goBack = false;
otherDoor.GetComponent<Animator>().SetBool("openDoor", true);
}
}