コード例 #1
0
        void Awake()
        {
            instance = this;

            //QualitySettings.vSyncCount=1;
            //Application.targetFrameRate=60;

            //get the unit in game
            player = (UnitPlayer)FindObjectOfType(typeof(UnitPlayer));

            //setup the collision rules
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerShootObject(), !shootObject);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerCollectible(), !collectible);

            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTerrain(), true);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTrigger(), true);

            //clear all the spawner and tracker sicne it's a new game
            UnitTracker.Clear();
            UnitSpawnerTracker.Clear();

            //this is not required, each individual unit and spawner will register itself to the tracker
            //UnitTracker.ScanForUnit();
            //UnitSpawnerTracker.ScanForSpawner();
        }
コード例 #2
0
ファイル: UnitPlayer.cs プロジェクト: shibuzhuan/CovKnight
        //turret facing
        public void AimTurretMouse(Vector3 mousePos)
        {
            if (destroyed || IsStunned())
            {
                return;
            }

            if (!enableTurretRotate || turretObj == null)
            {
                return;
            }

            if (turretAimMode == _TurretAimMode.ScreenSpace)
            {
                //get camera direction and mouse direction with repect to the player position on screen
                Vector3 camV = Quaternion.Euler(0, camT.eulerAngles.y, 0) * Vector3.forward;
                Vector3 dir  = (mousePos - Camera.main.WorldToScreenPoint(thisT.position)).normalized;
                dir = new Vector3(dir.x, 0, dir.y);

                float angleOffset = camT.eulerAngles.y;                   //get the camera y-axis angle
                float sign        = dir.x > 0 ? 1 : -1;                   //get the angle direction

                Vector3 dirM = Quaternion.Euler(0, angleOffset, 0) * dir; //rotate the dir for the camera angle, dir has to be vector3 in order to work

                Quaternion wantedRot = Quaternion.Euler(0, sign * Vector3.Angle(camV, dirM) + angleOffset, 0);
                if (!smoothTurretRotation)
                {
                    turretObj.rotation = wantedRot;
                }
                else
                {
                    turretObj.rotation = Quaternion.Slerp(turretObj.rotation, wantedRot, Time.deltaTime * 15);
                }
            }
            else if (turretAimMode == _TurretAimMode.Raycast)
            {
                LayerMask  mask = 1 << TDS.GetLayerTerrain();
                Ray        ray  = Camera.main.ScreenPointToRay(mousePos);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask))
                {
                    Vector3 point = new Vector3(hit.point.x, thisT.position.y, hit.point.z);

                    Quaternion wantedRot = Quaternion.LookRotation(point - thisT.position);
                    if (!smoothTurretRotation)
                    {
                        turretObj.rotation = wantedRot;
                    }
                    else
                    {
                        turretObj.rotation = Quaternion.Slerp(turretObj.rotation, wantedRot, Time.deltaTime * 15);
                    }
                }
            }
        }