Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

TRCGamez

Newbie
  • Content count

    4
  • Joined

  • Last visited

  • Days Won

    1

TRCGamez last won the day on May 14

TRCGamez had the most liked content!

Community Reputation

2 Neutral

About TRCGamez

  • Rank
    Newbie
  • Birthday December 15
  1. Regular Gun Script

    Here is a better script which is a little more advanced but comes with reloading, fire rate, and more! A lot of this is from Brackeys but quite a few things are from me too such as the shot sound animation etc. There also needs to be an animation so you will have to make that. If you do not want it simply remove all references to animations. If you would like to learn a little bit try to look at the script and understand it. I don't expect you to know about Coroutines or Enumerators. Just try to get a basic feel for C# through this script. Just ask for a script and I'll get it. Hope this helped!! using UnityEngine; using System.Collections; public class Guns : MonoBehaviour { public float damage = 25f; public float range = 100f; public GameObject impactEffect; public float hitForce = 30f; public float fireRate = 15f; public AudioSource gunshotSound; public int maxAmmo = 30; private int currentAmmo; public float reloadTime = 5f; private bool IsReloading = false; public Animation anim; public Camera fpsCam; public ParticleSystem muzzleFlash; private float nextTimeToFire = 0f; void Start () { anim = GetComponent<Animation>(); currentAmmo = maxAmmo; } // Update is called once per frame void Update () { if (IsReloading) return; if (currentAmmo <=0f) { StartCoroutine(Reload()); return; } if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire) { nextTimeToFire = Time.time + 1f/fireRate; SHOTSHOTSSHOTS.Play(); Shoot(); muzzleFlash.Play(); anim.Play("Shoot"); } } IEnumerator Reload () { IsReloading = true; Debug.Log ("Reloading..."); yield return new WaitForSeconds(reloadTime); currentAmmo = maxAmmo; IsReloading = false; } void Shoot () { currentAmmo--; RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); Target target = hit.transform.GetComponent<Target>(); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce (-hit.normal * hitForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } } }
  2. Regular Gun Script

    sure!
  3. Regular Gun Script

    Oh i forgot ! When you add the script there is a section for a muzzle flash! Look up how to make one, and then drag your muzzle flash into the slot! the muzzle flash will play and you will deal damage to whatever you put your target script in! f
  4. Regular Gun Script

    Hello! This is my first post ever! I just wanted to share a simple gun script that uses C#. Probably the best script for beginners! There are two scripts, one for the gun, and one for the enemies to shoot at! Hope u like it! 1st script: using UnityEngine; public class Gun : MonoBehaviour { public float damage = 25f; public float range = 100f; public Camera fpsCam; public ParticleSystem muzzleFlash; // Update is called once per frame void Update () { if (Input.GetButtonDown("Fire1")) { Shoot(); } } void Shoot () { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); Target target = hit.transform.GetComponent<Target>(); if (target != null) { target.TakeDamage(damage); } } } } 2nd Script (Target Script) using UnityEngine; public class Target : MonoBehaviour { public float health = 50f; //what makes the damage work public void TakeDamage (float amount) { health -= amount; if (health <= 0f) { Die(); } } void Die () { Destroy(gameObject); } } There u go! those are all of the scripts! (Credit to brackeys for them.)
×