Created
January 23, 2020 15:28
-
-
Save naylinhtun1/bb326b1e83fb0def42bda9b40685229a to your computer and use it in GitHub Desktop.
#Script #Gun #Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
//using static AutomaticGunScriptLPFP; | |
public class Gun : MonoBehaviour | |
{ | |
public float damage = 10f; | |
public float range = 30f; | |
public Camera Maincamera; | |
public ParticleSystem Muzzelflash; | |
public GameObject Flareeffect; | |
public float Muzzelforce = 30f; | |
//public AudioSource shootAudioSource; | |
//public soundClips SoundClips; | |
private void Update() | |
{ | |
if (Input.GetButtonDown("Fire1")) | |
{ | |
shoot(); | |
} | |
//void Start() | |
//{ | |
//shootAudioSource.clip = SoundClips.shootSound; | |
//} | |
void shoot() | |
{ | |
//shootAudioSource.Play(); | |
Muzzelflash.Play(); | |
RaycastHit hit; | |
if (Physics.Raycast(Maincamera.transform.position, Maincamera.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 * Muzzelforce); | |
} | |
GameObject MuzzelGO = Instantiate(Flareeffect, hit.point, Quaternion.LookRotation(hit.normal)); | |
Destroy(MuzzelGO, 2f); | |
} | |
} | |
} | |
} | |
its saying name target cant be found anyway to fix that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks