So i have this code to reset the car door in the start position when its’s closed, when this happens i want to play a sound. When i open the door i want to play a sound too.
Can anyone help please.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResetDoorPosition : MonoBehaviour {
private Audio
private bool shouldreset;
private Rigidbody rb;
private HingeJoint hj;
private JointLimits jl;
// Use this for initialization
void Start () {
shouldreset=false;
rb = GetComponent<Rigidbody> ();
hj = GetComponent<HingeJoint> ();
jl = GetComponent<HingeJoint> ().limits;
//rb.isKinematic = true;
rb.IsSleeping ();
}
// Update is called once per frame
void Update () {
//Debug.Log (transform.name +" : "+ hj.angle);
if (transform.name == "Tuer_Rechts") {
if (hj.angle < 0.000015f) {
shouldreset = false;
rb.velocity = Vector3.zero;
rb.IsSleeping ();
}
if (hj.angle > 0.15f) {
shouldreset = true;
rb.WakeUp ();
}
}
if (transform.name == "Tuer_Links") {
if (hj.angle > 0.000015f) {
shouldreset = false;
rb.velocity = Vector3.zero;
rb.IsSleeping ();
}
if (hj.angle < 0.15f) {
shouldreset = true;
rb.WakeUp ();
}
}
if (transform.name == "Kofferraumklappe") {
if (hj.angle > 0.000015f) {
shouldreset = false;
rb.velocity = Vector3.zero;
rb.IsSleeping ();
}
if (hj.angle < 0.15f && hj.angle > 55.0f) {
shouldreset = true;
rb.WakeUp ();
}
if (hj.angle < 54.0f) {
shouldreset = false;
rb.velocity = Vector3.zero;
rb.IsSleeping ();
}
}
}
}