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

How would i make my raycast script apply damage

$
0
0
Hello i have a raycast script, and i also have a damage script but how would i apply damage to objects when i shoot? [code]#pragma strict var endBarrel :Transform; var sound : AudioClip; var Damage : int = 10; function Update(){ var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0)); if(Input.GetButtonDown("Fire1")){ // you can use PlayOneShot to specify the sound... audio.PlayOneShot(sound); audio.Play(); } if (Input.GetMouseButtonDown(0)){ if (Physics.Raycast (endBarrel.position, transform.forward, 100)) { } } } [code] This is my damage script [code] var MaxHealth : int = 100; var CurrentHealth : int = 0; var Other : GameObject; function Start () { CurrentHealth = MaxHealth; } function Applydamage ( Damage : float) { if ( CurrentHealth < 0){ return; } CurrentHealth -= Damage; if ( CurrentHealth == 0){ Destroy( gameObject); } } [code]

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>