Any help would be grand!
I am trying to recieve the transform.position of a global Transform for a Spawn function.
Here’s what I am working with so far…
public class Creature_Movement : MonoBehaviour
{
public static Transform spawnPointForPlayer1;
public static void Spawn()
{
// reset the character's speed
movement.verticalSpeed = 0.0f;
movement.speed = 0.0f;
// reset the character's position to the spawnPoint
transform.position = Creature_Movement.spawnPointForPlayer1.transform.position;
}
}
So, what’s the problem? Although somewhat weird, this code should work. Static variables don’t appear in the Inspector - is this the problem? If so, you must assign the variable at runtime - maybe with a code like this:
void Start(){
// find the empty object named "PlayerSpawnPoint":
spawnPointForPlayer1 = GameObject.Find("PlayerSpawnPoint").transform;
}
But I wouldn’t use static functions and variables in this case - you will have trouble if more than one instance of this script exists, since a static variable is shared by all instances.