Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class WeaponController : MonoBehaviour {
- public Transform[] weapons;
- public int Mode;
- float time;
- float rate;
- float push;
- RaycastHit hit;
- //float damage;
- void Start () {
- }
- void Update () {
- rate = weapons[Mode].GetComponent("Weapon").rate;
- push = weapons[Mode].SendMessage("getPush");
- time += Time.deltaTime;
- if (Input.GetAxis("Fire") != 0 && time > rate) {
- Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
- if (Physics.Raycast(ray.origin, ray.direction, out hit)) {
- if (hit.rigidbody) hit.rigidbody.AddForce(ray.direction * push);
- }
- }
- }
- public void ChangeMode (int mode) {
- Mode = mode;
- for (int i=0; i < weapons.Length; i++) weapons[i].renderer.enabled = false;
- weapons[Mode].renderer.enabled = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement