Hi Guys, this is my first post hopefully its not too confusing.
I’m currently working through a Udemy course on unity “Ultimate guide to Game Development with Unity”. I have been adding a few features every now and again to make the game feel more natural/better. So I am up to a part where I wish to pick up a item (coin) by pressing the E key. I implimented it already but found if I add multiple coins in one area the game will pick them all up at once so I tried to make it so that if I look at the item I can pick it up. See the code below for reference:
private void OnTriggerStay(Collider other)
{
if (other.tag == "Player")
{
Ray rayOrigin2 = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hitInfo2;
Physics.Raycast(rayOrigin2, out hitInfo2, Mathf.Infinity);
if ((hitInfo2.transform == this.transform))
{
_uiManager.UpdateItemPickUpUI(this.gameObject);
Debug.Log(hitInfo2.transform.name);
if (Input.GetButton("Interact"))
{
Player _player = other.GetComponent<Player>();
if (_player != null)
{
_player.ItemPickUp(this.gameObject);
AudioSource.PlayClipAtPoint(_coinSound, Camera.main.transform.position, 1f);
Destroy(this.gameObject);
_uiManager.RemoveItemText();
}
}
}
else
{
_uiManager.RemoveItemText();
}
}
}
So basically I can only pick it up by looking at it. But when I enter game the text prompt (as seen below) never pops up unless I look upwards. Like either my coin is rising or my player is falling. But they are both stationary and on the ground. Any ideas what could be happening? Let me know if you want more details.
I have a character controller attached to the player and modified the player movement method a little bit cause I was falling off the side of the map still.