- Home /
Spawning Script Error
Here are my 2 scripts I am trying to create to make my Game object Spawn to a certain place, But I am getting this error.
Assets/Checkpoint.js(8,42): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.
Here is the first script for the checkpoint system:
----------------------------------------------------------------------------------------------
#pragma strict
static var ReachedPoint : Vector3;
function OnTriggerEnter (col : Collider)
{
if (col.tag == "Player")
{ if(UnityEngine.Transform.position.x > ReachedPoint.x )
{
ReachedPoint = transform.position;
}
}
}
----------------------------------------------------------------------------------------------
here is the script for the Ball Health system that uses the Checkpoint Script:
----------------------------------------------------------------------------------------------
#pragma strict
var maxFallDistance = -10;
private var isRestarting = false;
function Update () {
if(transform.position.y <= maxFallDistance)
{
if (isRestarting == false)
{
RestartLevel();
}
}
}
function RestartLevel (){
isRestarting = true;
//Application.LoadLevel("Level 01");
transform.position = Checkpoint.ReachedPoint;
}
----------------------------------------------------------------------------------------------
Do any of you know how to fix this error? Or what is wrong with any of the scripts?
Answer by Jessespike · Nov 15, 2015 at 08:13 AM
An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.
Error is saying you need to use an instance of Transform.
// Change this line:
if(UnityEngine.Transform.position.x > ReachedPoint.x )
// To this:
if(transform.position.x > ReachedPoint.x )
Your answer
Follow this Question
Related Questions
My Player can't move after respawning, help? 2 Answers
Checkpoint Question 0 Answers
How do I get an object to Instantiate infront of a specific object/player? 1 Answer
Spawn A prefab after death 3 Answers
Player spawning systems. 1 Answer