- Home /
I need help my teleporting script?Can anybody help me?
hi guys its david here,and today I have a problem with my script that I've been working on for the last 5 days that has only one error.take a look at my script an figure out whats the problem please someone.
using UnityEngine;
using System.Collections;
using System;
public class ClickObjectTeleport : MonoBehaviour
{
public int spawnVariance = 0;
private static System.Random random = new System.Random();
public bool showTeleportParticleEffect = true;
public GameObject teleportParticleGenerator;
public Transform teleportDestination;
void OnMouseOver()
{
if (Input.GetMouseButtonDown(0))
{
DoTeleport(teleportDestination);
}
}
void DoTeleport(Transform target)
{
string localPlayerName = LocalPlayer;
GameObject localPlayer = GameObject.Find(localPlayerName);
float offsetX = random.Next(spawnVariance);
float offsetZ = random.Next(spawnVariance);
Vector3 newPosition = target.position;
newPosition.x = target.position.x + offsetX;
newPosition.z = target.position.z + offsetZ;
localPlayer.transform.position = newPosition;
localPlayer.transform.rotation = target.rotation;
if (showTeleportParticleEffect)
{
if (teleportParticleGenerator != null)
{
Instantiate(teleportParticleGenerator, newPosition, target.rotation);
}
}
}
}
the error that I've had for 5 days is this:
Assets/ClickObjectTeleport.cs(24,42): error CS0103: The name `LocalPlayer' does not exist in the current context
can anybody help me on this please?
Answer by karljj1 · Feb 22, 2015 at 06:48 PM
LocalPlayer is used on line 24 but it is not defined anywhere inside of the class.
so
string localPlayerName = LocalPlayer; // What is LocalPlayer???
Perhaps this is something you want to define earlier ?
public int spawnVariance = 0;
private static System.Random random = new System.Random();
public bool showTeleportParticleEffect = true;
public GameObject teleportParticleGenerator;
public Transform teleportDestination;
public string LocalPlayer; // Here i am !
Your answer
Follow this Question
Related Questions
My mouse sensitivity value don't update in other function than sliderValueChange 0 Answers
How to use Animator Override Controler in script? 0 Answers
How to make player change into werewolf (script) 4 Answers
Particle System through Script 1 Answer
Please help my head is burning from this problem : i have multiple gameobject , same script 1 Answer