Game Development Reference
In-Depth Information
069 //Calculate hit
070
071 //Get ray from screen center target
072 Ray R = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2,
Screen.height/2,0));
073
074 //Test for ray collision
075 RaycastHit hit;
076
077 if(Physics.Raycast(R.origin, R.direction, out hit, Range))
078 {
079 //Target hit - check if target is enemy
080 if(hit.collider.gameObject.CompareTag("enemy"))
081 {
082 //Send damage message (deal damage to enemy)
083 hit.collider.gameObject.SendMessage("Damage",Damage,
SendMessageOptions.DontRequireReceiver);
084 }
085 }
086
087 //Reduce ammo
088 --Ammo;
089
090 //Check remaining ammo - post empty notification
091 if(Ammo <= 0) GameManager.Notifications.PostNotification(this, "AmmoExpired");
092
093 //Wait for recovery before re-enabling CanFire
094 yield return new WaitForSeconds(RecoveryDelay);
095
096 //Re-enable CanFire
097 CanFire = true;
098 }
099 //------------------------------------------------
100 //Called when animation has completed playback
101 public void SpriteAnimationStopped()
102 {
103 //If not equipped then exit
104 if(!IsEquipped) return;
105
106 //Show default sprite
107 DefaultSprite.enabled = true;
108 }
109 //------------------------------------------------
110 //Equip weapon
111 public bool Equip(WEAPON_TYPE WeaponType)
112 {
113 //If not this type, then exit and no equip
114 if((WeaponType != Type) || (!Collected) || (Ammo == 0) || (IsEquipped))
return false;
115
 
Search WWH ::




Custom Search