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

    2
  • 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

    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
  2. 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.)
×