Advertisement
Guest User

Untitled

a guest
Dec 12th, 2010
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WeaponController : MonoBehaviour {
  5.    
  6.     public Transform[] weapons;
  7.     public int Mode;
  8.     float time;
  9.     float rate;
  10.     float push;
  11.     RaycastHit hit;
  12.     //float damage;
  13.    
  14.     void Start () {
  15.  
  16.     }
  17.    
  18.     void Update () {
  19.        
  20.         rate = weapons[Mode].GetComponent("Weapon").rate;
  21.         push = weapons[Mode].SendMessage("getPush");
  22.        
  23.         time += Time.deltaTime;
  24.        
  25.         if (Input.GetAxis("Fire") != 0 && time > rate) {
  26.            
  27.             Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
  28.            
  29.             if (Physics.Raycast(ray.origin, ray.direction, out hit)) {
  30.                
  31.                 if (hit.rigidbody) hit.rigidbody.AddForce(ray.direction * push);
  32.         }
  33.         }
  34.        
  35.     }
  36.    
  37.     public void ChangeMode (int mode) {
  38.        
  39.         Mode = mode;
  40.         for (int i=0; i < weapons.Length; i++) weapons[i].renderer.enabled = false;
  41.         weapons[Mode].renderer.enabled = true;
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement