Hello. I have a problem and it has to do with assigning variables to objects when they're in the camera's field of view.
It sounds weird, I know, but I'm trying to make a body switch ability in my game where, if the player looks at an enemy and presses shift, they will switch places with said enemy. The problem is, I don't know how to add the enemy to the variable when the player looks at them. This is my current script, mainly compiled from other people's scripts:
using UnityEngine;
public class Move : MonoBehaviour
{
public GameObject Switcharoo;
void Swap() {
Vector3 temp = transform.position;
Vector3 turn = transform.rotation;
transform.position = Switcharoo.transform.position;
transform.rotation = Switcharoo.transform.rotation;
Switcharoo.transform.position = temp;
Switcharoo.transform.rotation = turn;
}
void Update()
{
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
if (Input.GetButtonDown("Swap"))
Swap();
}
}
Also, on a side-note, how do I save and load the player's rotation? I keep getting these 2 errors, but I'm new to C#, so I don't know what they mean: "Assets/Script/Move.cs(10,28): error CS0029: Cannot implicitly convert type 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'" "Assets/Script/Move.cs(14,35): error CS0029: Cannot implicitly convert type 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'"