Beispiel #1
0
        void StartShoot(RTSObject Enemy)
        {
            Vector3    startPosition  = new Vector3(rtsObject.ObjectTransform.position.x + rtsObject.HardRadius / 3, rtsObject.ObjectTransform.position.y + rtsObject.HardRadius / 3, -0.5f);         //стрелям с края борта
            CannonBall currentball    = cannonbal.Spawn(startPosition);
            Vector3    FinishPosition = new Vector3(Enemy.ObjectTransform.position.x + Random.Range(-Enemy.HardRadius / 2, Enemy.HardRadius / 2),
                                                    Enemy.ObjectTransform.position.y + Random.Range(-Enemy.HardRadius / 2, Enemy.HardRadius / 2), -0.5f);                                              //стреляем в случайное место на корабле

            Vector2 directionVector = FinishPosition - startPosition;
            float   angle           = Mathf.Atan2(directionVector.y, directionVector.x) * Mathf.Rad2Deg - 90;

            currentball.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            currentball.Finish = FinishPosition;
        }