using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GugusShoot : MonoBehaviour
{
public Transform Projectile;
public float DelayShoot = 1.0f;
float TimerShoot = 0;
public Transform SocketShoot;
GameObject Player;
public float Accuracy = 0.8f;
// Use this for initialization
void Start()
{
Player = GameObject.FindWithTag("Player");
if (Player == null)
Debug.LogError("Pas trouvé le joueur !!!! ??? ");
}
public void ShootProjectile()
{
//Vector3 posProjectile = this.transform.position;
Vector3 posProjectile = SocketShoot.position;
posProjectile += SocketShoot.forward * 1.0f;
Vector3 directionJoueur = Player.transform.position - this.transform.position;
directionJoueur = directionJoueur.normalized;
directionJoueur += Random.onUnitSphere * (1 - Accuracy);
directionJoueur = directionJoueur.normalized;
Transform proj = GameObject.Instantiate<Transform>(Projectile, posProjectile, Quaternion.identity);
proj.GetComponent<Rigidbody>().AddForce(directionJoueur * 20 +
this.transform.up * 1,
ForceMode.Impulse);
}
// Update is called once per frame
void Update()
{
Animator animator = this.GetComponent<Animator>();
TimerShoot -= Time.deltaTime;
if (TimerShoot <= 0)
{
TimerShoot = DelayShoot;
if (animator != null)
animator.SetBool("Attack", true);
}
else
{
if (animator != null)
animator.SetBool("Attack", false);
}
}
}