Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class CameraInAction : MonoBehaviour {
- public GameObject[] controlsUI;
- public GameObject startButton;
- private GameObject[] players;
- private Vector3 CamOldPos;
- private GameObject oldHitGO;
- private bool start_action = false;
- void Start () {
- CamOldPos = transform.position;
- players = GameObject.FindGameObjectsWithTag("Player");
- }
- void Update () {
- if (!start_action)
- MovingSquad ();
- }
- void CameraTarget () {
- gameObject.GetComponent<SmoothFollow>().target = players[Random.Range(0, players.Length)];
- oldHitGO = players[Random.Range(0, players.Length)];
- oldHitGO.GetComponent<GunController> ().underControl = true;
- }
- void CameraTop () {
- transform.position = CamOldPos;
- }
- public void StartAction () {
- start_action = true;
- foreach(var c in controlsUI){ c.SetActive(true);}
- startButton.SetActive(false);
- if(oldHitGO != null)
- {
- gameObject.GetComponent<SmoothFollow>().target = oldHitGO;
- oldHitGO.GetComponent<GunController> ().underControl = true;
- } else {
- CameraTarget();
- }
- }
- void MovingSquad () {
- Ray ray = gameObject.camera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Input.GetMouseButtonUp(0)) {
- if (Physics.Raycast (ray, out hit, Mathf.Infinity)) {
- if(hit.collider.tag != "Player" && oldHitGO != null){
- oldHitGO.transform.position = new Vector3(hit.point.x, oldHitGO.transform.position.y, hit.point.z); //присваиваем координаты
- oldHitGO.GetComponent<GunController> ().underControl = false; //отключаем управление
- oldHitGO = null; //удаляем управляемый объект
- }
- if (hit.collider.tag == "Player") { //Проверяем, если игрок нажал на одну из пушек, то берём её под управление
- if (oldHitGO != null)
- oldHitGO.GetComponent<GunController> ().underControl = false; //Выключаем управление у прошлой цели
- oldHitGO = hit.collider.gameObject; //Присваиваем новую цель
- oldHitGO.GetComponent<GunController> ().underControl = true; // включаем управление у новой цели
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement