Hi, so in my game I have one doorscript which I put on all door objects so when they are activated they should send the character to a certain position (which i manually input as a public Vector3) and a certain level (which I also manually input as a string) all through the inspector
heres the gist of the script:
using UnityEngine;
using System.Collections;
public class DoorScript : MonoBehaviour
{
GameObject player;
public bool unlocked;
public int Key;
Spells spells;
public bool LeadsToDifferentScene = false;
public string LevelItLeadsTo;
public Vector3 LocationItLeadsToInThatLevel;
public bool quantumLeap = false;
// Use this for initialization
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
spells = player.GetComponent(typeof(Spells)) as Spells;
}
public AudioClip lockedsound;
public AudioClip opensound;
// Update is called once per frame
void Update()
{
if (tag == "Active" && unlocked)
{
AudioSource.PlayClipAtPoint(opensound, transform.position);
if (!LeadsToDifferentScene && !quantumLeap)
{
player.transform.position += player.transform.up * 1f;
}
else if (LeadsToDifferentScene && !quantumLeap)
{
player.transform.localPosition = LocationItLeadsToInThatLevel;
Application.LoadLevel(LevelItLeadsTo);
} else{
player.transform.position = LocationItLeadsToInThatLevel;
}
tag = "Inactive";
}
else if (tag == "Active" && !unlocked)
{
if (spells.LookForKey(Key))
{
unlocked = true;
// play unlocke sound?
AudioSource.PlayClipAtPoint(opensound, transform.position);
if (!LeadsToDifferentScene)
{
player.transform.position += player.transform.up * 1f;
}
else if (LeadsToDifferentScene && !quantumLeap)
{
player.transform.localPosition = LocationItLeadsToInThatLevel;
Application.LoadLevel(LevelItLeadsTo);
} else{
player.transform.position = LocationItLeadsToInThatLevel;
}
tag = "Inactive";
}
else
{
AudioSource.PlayClipAtPoint(lockedsound, transform.position);
GameObject ohno = Instantiate(Resources.Load("Messages/OkMessage")) as GameObject;
OkMessage ohyes = ohno.GetComponent(typeof(OkMessage)) as OkMessage;
ohyes.message = "Locked";
tag = "Inactive";
}
}
}
}
On this particular door I have unlocked = true, leadstodifferentscene = true, levelitleadsto = MyLevelName, locationitleadstointhatlevel = the vector <17, 35, 0>, quantumleap = false.
It literally works for all of my ~20 doors that are in the game so far! For some reason this door isn’t working and it is sending the player to the position <4.92, 19.2, 7.14> a seemingly completely RANDOM position!!?
Is it because the level isn’t loading properly… or what? This door is exactly the same as this other door that leads to <6, 36, 0> in the SAME EXACT SCENE and it works perfectly.
ALSO I used player.transform.localPosition because I tried it with player.transform.position thinking it would fix it, but it doesn’t, it’s the exact same result. The player object is not a child to anything so it shouldn’t.
any ideas would be nice! thanks