using UnityEngine;
using System.Collections;
public class Shot : MonoBehaviour
{
public Rigidbody rocketPrefab;
public Transform barrelEnd;
public float speed=1000;
public GameObject crosshair;
bool isShoting = false;
RectTransform rt;
void Start()
{
RectTransform rt = crosshair.GetComponent<RectTransform>();
}
void Update()
{
if (isShoting == false)
{
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine (GetShot());
Rigidbody RocketInstance;
RocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
RocketInstance.AddForce(barrelEnd.forward * speed);
Destroy(RocketInstance.gameObject, 3);
}
}
}
public IEnumerator GetShot()
{
isShoting = true;
// HERE IS THE PROBLEM the script shoot the bullet and stop working
// If I disable this the shoting works nice again
//how can I make this without affecting the shot?
rt.sizeDelta = new Vector2(1000, 1000);
yield return new WaitForSeconds(0.4f);
isShoting = false;
}
}
if you are attempting to do some sort of automatic fire, GetButtonDown is only true for a single frame when the button is initially pushed…
1 Like