Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Ohyeahitsjosh's avatar
Ohyeahitsjosh
Honored Guest
10 years ago

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!

6 Replies

Replies have been turned off for this discussion
  • 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?
  • "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)'
  • Can you try it like this:

    GameObject.Find("FirstPersonCharacter").GetComponent<Camera>().transform.eulerAngles.x;
  • Unfortunately and ironically that brings back an error Unexpected symbol 'GetComponent'.

    Removing get component gives the same error with: Unexpected symbol <
  • That line of code seems to compile for me. What version of Unity are you using?
  • timsk's avatar
    timsk
    Honored Guest
    He's probably using UnityScript.

    Try:

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