Question by
sacercrisan · Feb 17, 2019 at 10:42 AM ·
directionaxisforward
How to make an item appear ahead of the camera?
I have a menu that I want to be able to toggle on and it will appear a few units (2 would be fine) ahead of the direction the camera is facing. Right now the menu indeed faces the current position cam is facing, but they're so close that I'm not able to select anything from that. Tried many things, yet no success. This is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIMovement : MonoBehaviour
{
public Camera mCam;
public GameObject menu;
public bool active = false;
void Start()
{
menu.SetActive(active);
}
void FixedUpdate()
{
this.transform.position = new Vector3(mCam.transform.position.x, mCam.transform.position.y + 0.5f, mCam.transform.position.z);
float angle_x = this.transform.eulerAngles.x;
float angle_y = this.transform.eulerAngles.y;
float angle_z = this.transform.eulerAngles.z;
this.transform.eulerAngles = new Vector3(angle_x, angle_y, angle_z);
if (Input.GetKeyDown(KeyCode.Space))
{
ToggleMenu();
}
}
public void ToggleMenu()
{
active = !active;
menu.SetActive(active);
if (active)
{
float angle_x = this.transform.eulerAngles.x;
float angle_y = mCam.transform.localEulerAngles.y;
float angle_z = this.transform.eulerAngles.z;
this.transform.eulerAngles = new Vector3(angle_x, angle_y, angle_z);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to translate Input axis into directions (in a 2D environment)? 0 Answers
How to calculate and use new direction angle as a new forward direction. 1 Answer
How to make a object move forward when is rotated. 0 Answers
Trying to get Player to shoot in both directions depending on what side he is facing? 0 Answers
Snap to grid 2 Answers