A couple of weeks ago when I wrote the following script, it worked just fine, teleporting the game object that I wanted teleported randomly around the scene.
When I loaded it up today I got this error: Assets/Teleport.cs(26,57): error CS1061: Type 'float' does not contain a definition for 'transform' and no extension method `transform' of type 'float' could be found. Are you missing an assembly reference?
I do not know what changed, or what to do to fix this. Any help is very much appreciated. Searching the error code, CS1061, has not helped me find an answer (most likely because I am not experienced enough to know what the heck people are talking about).
Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour {
public float Destination = Random.Range(0.0f,1.0f); // Gameobject where they will be teleported to
public string TagList = "|GoalBlock|"; // List of all tags that can teleport
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnTriggerEnter(Collider other)
{
// If the tag of the colliding object is allowed to teleport
if (TagList.Contains(string.Format("|{0}|", other.tag)))
{
// Update other objects position and rotation
gameObject.transform.position = Destination.transform.position;
gameObject.transform.rotation = Destination.transform.rotation;
}
}
}
↧