using StarterAssets;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Bullet : MonoBehaviour
{
private StarterAssetsInputs _input;
public GameObject prefabBullet;
public GameObject bulletPoint;
public float SpeedBullet;
public Animator anim;
private bool isShooting = false;
private float animParameter = 0f;
// Start is called before the first frame update
void Start()
{
_input = GetComponent<StarterAssetsInputs>();
}
// Update is called once per frame
void Update()
{
if (_input.shoot && !isShooting)
{
_input.shoot = false;
StartCoroutine(Serang());
}
}
public void Shoot()
{
}
IEnumerator Serang()
{
isShooting = true;
// Set parameter float untuk memulai animasi serangan
animParameter = 0.5f;
// Tunggu sebentar untuk memberikan waktu animasi serangan dimainkan
yield return new WaitForSeconds(0.5f);
// Buat peluru
GameObject bullet = Instantiate(prefabBullet, bulletPoint.transform.position, transform.rotation);
bullet.GetComponent<Rigidbody>().AddForce(transform.forward * SpeedBullet);
Destroy(bullet, 2f);
// Set parameter float untuk kembali ke animasi tangan ke belakang
animParameter = 1f;
// Tunggu sebentar sebelum memulai animasi idle tangan
yield return new WaitForSeconds(0.5f);
// Set parameter float untuk memulai animasi idle tangan
animParameter = 0f;
// Setelah selesai, kembalikan parameter ke 0
isShooting = false;
}
void LateUpdate()
{
// Set parameter float pada animator
anim.SetFloat("Gaskeun", animParameter);
}
}