Hi,
i want to open a door and i have 3 scripts.
First Script (Select) Assigned to GameCamera:
void Update () {
Ray ray = transform.camera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2,0));
if ( Physics.Raycast(ray, out hit,4) && hit.collider.gameObject.GetComponent<Interact>() != null)
{
hit.collider.gameObject.GetComponent<Interact>().OnLookEnter();
}
}
Second Script (Interact) Assigned to any Object i want to interact with (in this case the door:
void Update ()
{
canInteract = false;
renderer.material.shader = origShader;
}
public void OnLookEnter()
{
canInteract = true;
renderer.material.shader = Shader.Find("Self-Illumin/Bumped Diffuse");
}
Third Script (OpenDoor) Assigned to the Door to open
void Update ()
{
canInteract = this.GetComponent<Interact>().canInteract;
if (open == true)
{
var target = Quaternion.Euler(0,DoorOpenAngle,0);
door.localRotation = Quaternion.Slerp(door.localRotation,target,Time.deltaTime * smooth);
}
if (open == false)
{
var target1 = Quaternion.Euler(0,DoorCloseAngle,0);
door.localRotation = Quaternion.Slerp(door.localRotation,target1,Time.deltaTime * smooth);
}
if (canInteract)
{
if (Input.GetMouseButtonDown(0))
{
if (open == false)
{
(open) = true;
}
else
{
(open) = false;
}
this.PlayOpenDoorSound();
}
}
}
so if i walk to the door, the “canInteract” from the Interact script changes right, but the door “canInteract” which references to the “canInteract” from the Interact-Sript in the openDoor script does not Change.
What did i wrong ?
Thx!