So I am attempting to create a door that rotates around a hinge, when a button is activated through Raycast it does not print the “Debug.Log(“Button pressed”)” to the console at all. Is there any other way i can improve upon the raycast method to guarantee a raycast hit, like using an empty from which the raycast originates. Then the RotateAround does not give code error, yet is does not rotate around the object designated as center/point of origin. Is there something wrong in my code.
using UnityEngine;
using System.Collections;
public class Switch : MonoBehaviour {
public Transform door;
public Transform doorHinge;
public float angle = 20;
void update () {
RaycastHit hit;
if (Input.GetKeyDown(KeyCode.E))
{
if (Physics.Raycast(transform.position, transform.forward, out hit, 2.0F))
{
if(hit.transform.tag == "Button")
{
door.RotateAround(doorHinge.position, Vector3.up, angle * Time.deltaTime);
Debug.Log("Button pressed");
}
}
}
}
}
Please point in right direction or help with code and thanks in advance for the help.
so i tried it with hit.transform.gameObject.tag and still no result. With hit.gameObject.tag it gives an error. Is there any documentation or tutorials that shows some techniques in using raycast. I tried looking and anything I find does not thoroughly explain it. It just shows me what I know. Sadly this Unity - Scripting API: Physics.Raycast its not helping either.
what is this script attached to? and can you explain in words what you are trying to achieve with the raycast? (check the player is near enough to the button?)
Ok I have the script attached to the player prefab(I also tried attaching it to the button). I have the objects that I want to rotate around assigned to the script. What I’m trying to achieve with the raycast is to have the player look at an object tagged with button and if they press a certain key it opens the door a few degrees(degrees controlled through the script). Hopefully that makes sense, I’m prone to have grammar errors. Thanks in advance.