예제 #1
0
 public void instantRefresh()
 {
     if (_bot != null)
     {
         transform.position    = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
         transform.eulerAngles = OrientationVector.createFrom(_bot.Orientation);
         lastPlayedAnim        = null;
     }
 }
예제 #2
0
        void Update()
        {
            if (_bot != null)
            {
                if (_bot.LastAction != LastAction.ScriptError)
                {
                    _exclamationMarkVisible = false;
                    if (exclamationMark != null)
                    {
                        Destroy(exclamationMark);
                    }
                }

                if (_bot.PhysicalHealth.Current <= 0 && _bot.LastAction != LastAction.SelfDestruct)
                {
                    GoAnimOnce(DEATH);
                }
                else
                {
                    Vector3 targetDir    = OrientationVector.createFrom(_bot.Orientation);
                    float   rotationStep = rotationSpeed * Time.deltaTime;
                    Vector3 newDir       = Vector3.RotateTowards(transform.forward, targetDir, rotationStep, 0.0F);
                    if (targetDir != newDir)
                    {
                        transform.rotation = Quaternion.LookRotation(newDir);
                    }

                    float   step = speed * Time.deltaTime;
                    Vector3 targetWorldPosition = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
                    Vector3 newPos = Vector3.MoveTowards(transform.position, targetWorldPosition, step);
                    if ((targetDir - newDir).magnitude > 0.01)
                    {
                        GoAnim(TURN_RIGHT);
                    }
                    else if ((newPos - transform.position).magnitude > 0.01)
                    {
                        GoAnim(WALK);
                    }
                    else
                    {
                        switch (_bot.LastAction)
                        {
                        case LastAction.MeleeAttack:
                            GoAnim(MELEE_ATTACK);
                            break;

                        case LastAction.RangedAttack:
                            if (rangeAttack == null && !_rangeAttackFired)
                            {
                                _rangeAttackFired = true;
                                rangeAttack       = Instantiate(rangeAttackPrefab);
                                //rangeAttack.transform.SetParent(this.transform);
                                RangeAttackController rangeAttackController = rangeAttack.GetComponent <RangeAttackController>();
                                Vector3 startPos  = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
                                Vector3 targetPos = GridController.Instance.gridToWorldPosition(_bot.LastAttackLocation.X, _bot.LastAttackLocation.Y);
                                rangeAttackController.fire(startPos, targetPos, 3f);
                                GoAnim(RANGED_ATTACK);
                            }
                            break;

                        case LastAction.SelfDestruct:
                            GetComponent <ExploderController>().Do(x => x.Explode());
                            GoAnimOnce(DEATH);
                            break;

                        case LastAction.ScriptError:
                            if (!_exclamationMarkVisible)
                            {
                                exclamationMark = Instantiate(exclamationMarkPrefab);
                                exclamationMark.transform.SetParent(head);
                                exclamationMark.transform.localPosition = new Vector3(0, 0, 0);
                                exclamationMark.transform.position      = new Vector3(exclamationMark.transform.position.x, 2.5f, exclamationMark.transform.position.z);
                                _exclamationMarkVisible = true;
                            }
                            break;

                        default:
                            GoAnim(IDLE);
                            break;
                        }
                    }
                    transform.position = newPos;

                    Debug.DrawRay(transform.position, newDir, Color.red);
                }
            }
        }