Exemple #1
0
        void LateUpdate()
        {
            if (!currentTankController || !currentGunController)
            {
                UIRoot.SetActive(false);
                return;
            }

            if (!currentTankController.canControl || !currentTankController.gameObject.activeInHierarchy || !currentTankController.enabled)
            {
                if (disableUIWhenNoVehicle)
                {
                    UIRoot.SetActive(false);
                }
                return;
            }

            if (!UIRoot.activeInHierarchy)
            {
                UIRoot.SetActive(true);
            }

            projectileName.text = currentGunController.projectile.name;

            if (!currentGunController.reloading)
            {
                currentAmmo.text = currentGunController.currentAmmo.ToString();
            }
            else
            {
                currentAmmo.text = "R";
            }

            if (crosshair)
            {
                if (!mainCamera)
                {
                    mainCamera = GameObject.FindObjectOfType <RTC_MainCamera> ();
                    return;
                }

                Vector3 vpPosition = mainCamera.cam.WorldToViewportPoint(currentGunController.directedTarget.position);
                crosshair.transform.position = mainCamera.cam.WorldToViewportPoint(currentGunController.directedTarget.position);

                Vector3 pos;
                pos.x = rectTransform.rect.width * vpPosition.x - rectTransform.rect.width / 2f;
                pos.y = rectTransform.rect.height * vpPosition.y - rectTransform.rect.height / 2f;
                pos.z = 0f;

                crosshair.transform.localPosition = pos;
            }

            if (tankRotation)
            {
                tankRotation.rectTransform.localRotation = Quaternion.Euler(0f, 0f, currentGunController.rotationOfTheGun);
            }
        }
        private void Start()
        {
            // find the camera in the object hierarchy
            m_Cam          = GetComponentInChildren <Camera>().transform;
            RTCCamera      = GetComponentInParent <RTC_MainCamera> ();
            m_Pivot        = m_Cam.parent;
            m_OriginalDist = m_Cam.localPosition.magnitude;
            m_CurrentDist  = m_OriginalDist;

            // create a new RayHitComparer
            m_RayHitComparer = new RayHitComparer();
        }
        void Awake()
        {
            tankRigid    = GetComponent <Rigidbody>();
            mainGunRigid = mainGun.GetComponent <Rigidbody>();
            tank         = gameObject.GetComponent <RTC_TankController>();
            tankCamera   = GameObject.FindObjectOfType <RTC_MainCamera>();

            GameObject newTarget = new GameObject("Located Target");

            locatedTarget = newTarget.transform;

            GameObject newTarget2 = new GameObject("Directed Target");

            directedTarget = newTarget2.transform;

            mainGunRigid.maxAngularVelocity = maximumAngularVelocity;
            mainGunRigid.interpolation      = RigidbodyInterpolation.None;
            mainGunRigid.interpolation      = RigidbodyInterpolation.Interpolate;

#if RTC_REWIRED
            player = Rewired.ReInput.players.GetPlayer(0);
                #endif
        }