Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Shoot : MonoBehaviour
- {
- public Transform _thePrefab;
- public int forceSpeed = 10000;
- public int fireMinDelay_ms = 500;
- public int fireMaxDelay_ms = 1000;
- private float nextFire = 0.0f;
- private float delay;
- void Start()
- {
- }
- void CannonFire (Transform fire_position)
- {
- Transform prefabInstance = (Transform) Instantiate(_thePrefab, fire_position.position,Quaternion.identity);
- prefabInstance.rigidbody.AddForce(fire_position.forward * forceSpeed);
- }
- // Update is called once per frame
- void Update ()
- {
- if (nextFire != 0.0f && Time.time > nextFire)
- {
- nextFire = 0.0f;
- var fire_position = transform.Find("SpawnPoint");
- CannonFire(fire_position.transform);
- }
- if (Input.GetMouseButtonDown(0) && nextFire == 0.0f)
- {
- delay = Random.Range(fireMinDelay_ms,fireMaxDelay_ms)/1000.0f;
- nextFire = Time.time + delay;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement