Skip to main content
Up and Coming
August 10, 2015

Rotation to teleport

Hey everyone,

I'm back again with another problem (seriously, I'm the LAST person on earth who should be programming). Essentially, I'm trying to teleport the player when they rotate on a teleportation pad (think Star Trek). However, I'm trying to get information from the first person camera and I can't quite get it to work.


using UnityEngine;
using System.Collections;
using UnityEngine.VR;

public class RotateTeleporter : MonoBehaviour {

private bool playerInTeleporter;
private float playerInitialDirection;
Camera mycamera;


// Use this for initialization
void Start () {
playerInTeleporter = false;
playerInitialDirection = 0;
}

// Update is called once per frame
void Update () {


}

void OnTriggerEnter (Collider trig){
playerInitialDirection = GameObject.Find("FirstPersonCharacter").camera.transform.eulerAngles.x;
playerInTeleporter = true;

}
}


Apparently
playerInitialDirection = GameObject.Find("FirstPersonCharacter").camera.transform.eulerAngles.x;
is outdated according to Unity. How should I write this? All I'm trying to do is teleport the player when they're on the pad and then rotate 180 degrees. Thanks!
    This topic has been closed for replies.

    6 replies

    Inspiring
    August 10, 2015
    Well, if you are trying to determine the yaw value (looking left or right) you want to be checking the y axis.

    That code looks like it would compile. What is the actual error/warning that Unity is giving?
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    August 10, 2015
    "cybereality" wrote:
    Well, if you are trying to determine the yaw value (looking left or right) you want to be checking the y axis.

    That code looks like it would compile. What is the actual error/warning that Unity is giving?


    It is giving me this back:

    assets/Scripts/RotateTeleporter.cs(25,82): error CS0619: `UnityEngine.GameObject.camera' is obsolete: `Property camera has been deprecated. Use GetComponent<Camera>() instead. (UnityUpgradable)'
    Inspiring
    August 10, 2015
    Can you try it like this:

    GameObject.Find("FirstPersonCharacter").GetComponent<Camera>().transform.eulerAngles.x;
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    August 10, 2015
    Unfortunately and ironically that brings back an error Unexpected symbol 'GetComponent'.

    Removing get component gives the same error with: Unexpected symbol <
    Inspiring
    August 10, 2015
    That line of code seems to compile for me. What version of Unity are you using?
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Participant
    August 11, 2015
    He's probably using UnityScript.

    Try:

    playerInitialDirection = GameObject.Find("FirstPersonCharacter").GetComponent(Camera).transform.eulerAngles.x;