Hi there!
I am very new to Unity and scripting, and I havent been able to figure this problem out on my own.
I have a player character, that is created in its own scene, and then preserved when changing scenes. When i decide to apply this piece of script into triggering object(Object that is supposed to move player a bit)
private var playerObject : GameObject;
function OnTriggerEnter(collisionInfo : Collider)
{
if(collisionInfo.gameObject.tag == "Player")
{
playerObject.transform.position = Vector3 (1,-8,6);
}
}
I cannot select the playerobject to the script because it doesnt exist in that scene yet.
Now how should/could I properly circumvent this problem, or am I just being a bit silly again?
-EDIT-
I may ha been a bit unclear. I have this object called TriggerButton, which contains the script. Triggerbutton is sitting nicely in its own scene, and waiting for player to come and collide with it. if(collisionInfo.gameObject.tag == "Player") <-This line is already in use and working. What is not working, is that playerObject (tag: Player) does not change its position at collision with TriggerButton, even though other events (playing sound, changing variables) which I left out of this code work perfectly.
-EDIT 2-
Here is the full script: Since I cannot paste long scripts into comments, I made this new "answer" so I could paste the entire script I am using. I did also make some changes to it, but they dont seem to help.
var triggerusable = false;
var playerObject : GameObject;
function OnTriggerEnter(collisionInfo : Collider)
{
print("Collision");
if(collisionInfo.gameObject.tag == "Player")
{
triggerusable=true;
print("You Can Use this thing!");
}
}
function OnTriggerExit(collisionInfo : Collider)
{
print("Collision NOT");
if(collisionInfo.gameObject.tag == "Player")
{
TextfieldTest.texttestvisible = false;
TextfieldTest.texttestphase = 0;
triggerusable=false;
print("NotColliding!");
}
}
function FixedUpdate()
{
if(Input.GetButton("e")) //-
{
if(triggerusable)
{
print("USED!");
triggerusable = false;
TextfieldTest.texttestvisible = true;
TextfieldTest.texttestphase = 1;
playerObject.transform.position = Vector3 (-63.7896,-0.2890768,-3.386028); //This line seems to do nothing, but if I chancge targeted gameobject while running the game it works perfectly.
}
else
{
print("Not Usable Anymore");
}
}
}