Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ProjectileShooter : MonoBehaviour{
- public GameObject prefab;
- public float timeBetweenShots;
- public bool CarryingWeapon = false;
- private float timeShots;
- void Start () {
- prefab = Resources.Load("projectile") as GameObject;
- }
- // Update is called once per frame
- void Update () {
- timeShots += Time.deltaTime;
- if (Input.GetMouseButtonDown(0) && timeShots >= timeBetweenShots)
- CarryingWeapon = true;
- {
- timeShots = 0;
- GameObject projectile = Instantiate(prefab) as GameObject;
- projectile.transform.position=transform.position+Camera.main.transform.forward * 2;
- Rigidbody rb = projectile.GetComponent<Rigidbody>();
- rb.velocity=Camera.main.transform.forward * 40;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement