70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LobbyDummyController : MonoBehaviour
|
|
{
|
|
[SerializeField] private float speed;
|
|
private bool movingLeft = false;
|
|
|
|
[System.NonSerialized] public bool hitBody = false;
|
|
[System.NonSerialized] public bool hitHead = false;
|
|
|
|
private AudioSource dummySource;
|
|
private AudioClip bodyShotSound;
|
|
private AudioClip headShotSound;
|
|
|
|
private Animator anim;
|
|
|
|
private void Awake()
|
|
{
|
|
anim = transform.GetChild(0).GetComponent<Animator>();
|
|
dummySource = GetComponent<AudioSource>();
|
|
bodyShotSound = OnDemandLoader.Load<AudioClip>("Music/Sounds/dummyBodyHit");
|
|
headShotSound = OnDemandLoader.Load<AudioClip>("Music/Sounds/dummyHeadHit");
|
|
}
|
|
void Start()
|
|
{
|
|
movingLeft = true;
|
|
}
|
|
void Update()
|
|
{
|
|
if (movingLeft)
|
|
{
|
|
transform.Translate(Vector3.left * speed * Time.deltaTime);
|
|
if (transform.localPosition.x <= -4.72f) { movingLeft = false; }
|
|
}
|
|
else
|
|
{
|
|
transform.Translate(Vector3.right * speed * Time.deltaTime);
|
|
if (transform.localPosition.x >= 18.0f) { movingLeft = true; }
|
|
}
|
|
|
|
if(hitHead)
|
|
{
|
|
//Debug.Log("HIT HEAD");
|
|
anim.SetTrigger("headShot");
|
|
RandomizedPitch(headShotSound);
|
|
hitHead = false;
|
|
}
|
|
if(hitBody)
|
|
{
|
|
//Debug.Log("Hit BODY!");
|
|
anim.SetTrigger("bodyShot");
|
|
RandomizedPitch(bodyShotSound);
|
|
hitBody = false;
|
|
}
|
|
}
|
|
|
|
private void RandomizedPitch(AudioClip clip)
|
|
{
|
|
float randPitch = Random.Range(0.85f, 1.15f);
|
|
|
|
dummySource.pitch = randPitch;
|
|
dummySource.PlayOneShot(clip);
|
|
}
|
|
|
|
|
|
|
|
}
|