Beispiel #1
0
    void Awake()
    {
        gameObject.TryGetComponent <CharacterController> (out controller);

        AtomTags.OnInitialization(() => player = AtomTags.FindByTag(playerTag.Value));

        StateMachineRef.Machine.OnUpdate((deltaTime, value) =>
        {
            distance = Vector3.Distance(player.transform.position, transform.position);

            if (value == "CHASING")
            {
                if (player != null)
                {
                    MoveTowardsPlayer();
                }
            }
            else if (value == "ATTACKING")
            {
            }
        }, gameObject);

        StateMachineRef.Machine.OnStateCooldown("ATTACKING", (state) => print("FIRE"), gameObject);

        StateMachineRef.Machine.DispatchWhen(
            command: "ATTACK",
            (value) => player != null && value == "CHASING" && (_shootingRange.Value >= Vector3.Distance(player.transform.position, transform.position)),
            gameObject
            );

        StateMachineRef.Machine.DispatchWhen(
            command: "CHASE", (value) => player.transform != null && value == "ATTACKING" && (_shootingRange.Value < Vector3.Distance(player.transform.position, transform.position)), gameObject);
    }
Beispiel #2
0
        void Awake()
        {
            Transform target = null;

            AtomTags.OnInitialization(() => target = AtomTags.FindByTag(_tagToTarget.Value).transform);

            _enemyState.Machine.OnStateCooldown("ATTACKING", (value) =>
            {
                if (target)
                {
                    var spawnPos = transform.position + transform.right;
                    Instantiate(_projectile, spawnPos, transform.rotation);
                }
            }, gameObject);
        }
Beispiel #3
0
        void Awake()
        {
            Transform target = null;

            AtomTags.OnInitialization(() => target = AtomTags.FindByTag(_tagToTarget.Value).transform);
            var body = GetComponent <Rigidbody2D>();

            _enemyState.Machine.OnUpdate((deltaTime, value) =>
            {
                if (target)
                {
                    body.Move((target.position - transform.position), value == "CHASING" ? 2f : 0f, deltaTime);
                }
                else
                {
                    body.Move(Vector2.zero, 0f, deltaTime);
                }
            }, gameObject);
            _enemyState.Machine.DispatchWhen(command: "ATTACK", (value) => target != null && value == "CHASING" && (_shootingRange.Value >= Vector3.Distance(target.position, transform.position)), gameObject);
            _enemyState.Machine.DispatchWhen(command: "CHASE", (value) => target != null && value == "ATTACKING" && (_shootingRange.Value < Vector3.Distance(target.position, transform.position)), gameObject);
        }