Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Need help with shooting and reload script

$
0
0
Hello, I have a shooting script that Instantiates bullets when the mouse0 button is pressed also it sends a ray cast to make bullet holes when the ray cast hits the walls. This is good but now I want to add a reload function ,I have an idea of how to do this but I don't really know how to put it into code (I'm not a beginner). I would also like it to have a reload animation. thanks :) using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public GameObject bullet; public GameObject bulletHole; public float delayTime = 2f; private float counter = 0f; void Update () { } void FixedUpdate () { if (Input.GetKey (KeyCode.Mouse0) && counter > delayTime) { Instantiate(bullet, transform.position, transform.rotation); GetComponent().Play(); counter = 0; RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 70f)) { Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); } } counter += Time.deltaTime; } } Im not sure if this is needed but here is the script for the bullet. using UnityEngine; using System.Collections; public class MoveBullet : MonoBehaviour { public float speed = 1f; void Start () { } void Update () { transform.Translate (0, 0, speed); } }

Viewing all articles
Browse latest Browse all 592

Trending Articles