my door animation is set to automatic how to make it when pressing a key
Options
RoyKent
✭
it will mean alot if someone can help with this, im kinda new to scripting but im getting better day by day, anyway i have a script got it from the forum, its an automatic door opening i made some changes to it, however i want it to be when i press a key like ( if (Input.GetKeyDown(KeyCode.F)) the bool active and the door opens, not automatically as it is now, this is the script
using UnityEngine;
using System.Collections;
using Photon.Pun;
[RequireComponent(typeof(PhotonView))]
[RequireComponent(typeof(PhotonAnimatorView))]
public class DoorOpenClose : MonoBehaviourPun
{
//PhotonView photonView = PhotonView.Get(this);
public bool enter = false;
Animator anim;
public AudioClip doorOpenClip;
public AudioClip doorCloseClip;
void Start()
{
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
photonView.RPC("openDoor", RpcTarget.All, null);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
photonView.RPC("closeDoor", RpcTarget.All, null);
}
}
[PunRPC]
void closeDoor()
{
//Debug.Log("Trigger Exit");
(enter) = false;
anim.SetBool("Open", false);
GetComponent<AudioSource>().clip = doorCloseClip;
GetComponent<AudioSource>().Play();
}
[PunRPC]
void openDoor()
{
//Debug.Log("Trigger Enter");
(enter) = true;
anim.SetBool("Open", true);
GetComponent<AudioSource>().clip = doorOpenClip;
GetComponent<AudioSource>().Play();
}
}
using UnityEngine;
using System.Collections;
using Photon.Pun;
[RequireComponent(typeof(PhotonView))]
[RequireComponent(typeof(PhotonAnimatorView))]
public class DoorOpenClose : MonoBehaviourPun
{
//PhotonView photonView = PhotonView.Get(this);
public bool enter = false;
Animator anim;
public AudioClip doorOpenClip;
public AudioClip doorCloseClip;
void Start()
{
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
photonView.RPC("openDoor", RpcTarget.All, null);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
photonView.RPC("closeDoor", RpcTarget.All, null);
}
}
[PunRPC]
void closeDoor()
{
//Debug.Log("Trigger Exit");
(enter) = false;
anim.SetBool("Open", false);
GetComponent<AudioSource>().clip = doorCloseClip;
GetComponent<AudioSource>().Play();
}
[PunRPC]
void openDoor()
{
//Debug.Log("Trigger Enter");
(enter) = true;
anim.SetBool("Open", true);
GetComponent<AudioSource>().clip = doorOpenClip;
GetComponent<AudioSource>().Play();
}
}
0