Exemple #1
0
        private void Update()
        {
            float           angleCamUnit = Vector3.Angle(trCamera.forward, trUnit.forward);
            AvatarDirection avatar       = avatarConfig.GetAvatarByAngle(angleCamUnit);

            bool isFlip = false;

            if (avatar.IsCanFlip)
            {
                Vector3 cross = Vector3.Cross(trCamera.forward, trUnit.forward);
                isFlip = cross.y < 0;
            }

            rendererModel.sprite = avatar.Idle;
            rendererModel.flipX  = isFlip;
        }
Exemple #2
0
        public AvatarDirection GetAvatarByAngle(float directionAngleDeg)
        {
            float           smallestLengVel = float.MaxValue;
            AvatarDirection best            = avatarDirections[0];

            foreach (var item in avatarDirections)
            {
                float angleDiff = Mathf.Abs(Mathf.DeltaAngle(directionAngleDeg, item.AngleDeg));

                if (angleDiff < smallestLengVel)
                {
                    best            = item;
                    smallestLengVel = angleDiff;
                }
            }

            return(best);
        }