JumpScare Script Problem

Hello, Transform.Position don’t work, why?

var gameobject : GameObject;
var Seconds = 1.0;

function Start (){
gameobject.GetComponent.().enabled = false;
}

function OnTriggerEnter (col:Collider){
gameobject.GetComponent.().enabled = true;
transform.position.x += 5;
yield WaitForSeconds (5);
Destroy();
}

function Destroy(){
Destroy(gameobject);
}

You can’t set a component of a Vector3 directly. Instead, use transform.position += new Vector3(5,0,0);.

Don’t work :confused:

Hmm, I see that you define a “gameobject” variable and never initiate it, so I imagine you are controlling a different game object through this script by dragging it in the inspector. However, then you use transform.position, which will affect the transform of the game object the script is attached to instead of your “gameobject” variable. Use “gameobject.transform.position” instead, or, even better, don’t use that “gameobject” variable at all and instead apply the script directly to the object you wish to affect.