alem da musica nenhum dos audios querem reproduzir
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControlaAudio : MonoBehaviour
{
private AudioSource MeuAudioSource;
public static AudioSource instancia;
void Awake()
{
MeuAudioSource = GetComponent<AudioSource>();
instancia = MeuAudioSource;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ControlaJogador : MonoBehaviour
{
public float Velocidade = 10;
private Vector3 direcao;
public LayerMask MascaraChao;
public GameObject TextoGameOver;
private Rigidbody rigidbodyJogador;
private Animator animatorJogador;
public int Vida = 100;
public ControlaInterface scriptControlaInterface;
public AudioClip SomDeDano;
private void Start()
{
Time.timeScale = 1;
rigidbodyJogador = GetComponent<Rigidbody>();
animatorJogador = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
float eixoX = Input.GetAxis("Horizontal");
float eixoZ = Input.GetAxis("Vertical");
direcao = new Vector3(eixoX, 0, eixoZ);
if (direcao != Vector3.zero)
{
animatorJogador.SetBool("Movendo", true);
}
else
{
animatorJogador.SetBool("Movendo", false);
}
if(Vida <= 0)
{
if(Input.GetButtonDown("Fire1"))
{
SceneManager.LoadScene("game");
}
}
}
void FixedUpdate()
{
rigidbodyJogador.MovePosition
(rigidbodyJogador.position +
(direcao * Velocidade * Time.deltaTime));
Ray raio = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(raio.origin, raio.direction * 100, Color.red);
RaycastHit impacto;
if(Physics.Raycast(raio, out impacto, 100, MascaraChao))
{
Vector3 posicaoMiraJogador = impacto.point - transform.position;
posicaoMiraJogador.y = transform.position.y;
Quaternion novaRotacao = Quaternion.LookRotation(posicaoMiraJogador);
rigidbodyJogador.MoveRotation(novaRotacao);
}
}
public void TomarDano (int dano)
{
Vida -= dano;
ControlaAudio.instancia.PlayOneShot(SomDeDano);
scriptControlaInterface.AtualizarSliderVidaJogador();
if(Vida <= 0)
{
Time.timeScale = 0;
TextoGameOver.SetActive(true);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControlaArma : MonoBehaviour {
public GameObject Bala;
public GameObject CanoDaArma;
public AudioClip SomDeTiro;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire1"))
{
Instantiate(Bala, CanoDaArma.transform.position, CanoDaArma.transform.rotation);
ControlaAudio.instancia.PlayOneShot(SomDeTiro);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bala : MonoBehaviour {
public float Velocidade = 20;
private Rigidbody rigidbodyBala;
public AudioClip SomDaMorte;
private void Start()
{
rigidbodyBala = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
rigidbodyBala.MovePosition
(rigidbodyBala.position +
transform.forward * Velocidade * Time.deltaTime);
}
void OnTriggerEnter(Collider objetoDeColisao)
{
if(objetoDeColisao.tag == "Inimigo")
{
Destroy(objetoDeColisao.gameObject);
ControlaAudio.instancia.PlayOneShot(SomDaMorte);
}
Destroy(gameObject);
}
}