示例#1
0
 void OnGameStart()
 {
     _enabled  = true;
     _curState = UFOState.Idle;
     startTime = Time.time;
     waitTime  = Random.Range(minWaitTime, maxWaitTime);
 }
示例#2
0
    IEnumerator PerformState(UFOState state, float lengthInSeconds)
    {
        isExecutingState = true;
        currentState     = state;
        float stateRemaining = 0.0f;

        while (stateRemaining < lengthInSeconds)
        {
            switch (currentState)
            {
            case UFOState.Stopped:
                break;

            case UFOState.Observing:
                Observe();
                break;

            case UFOState.Moving:
                Move();
                break;
            }

            stateRemaining += Time.deltaTime;
            yield return(null);
        }

        currentState     = nextState;
        isExecutingState = false;
    }
示例#3
0
    void dropPucks()
    {
        int puckCount = Random.Range(minItems, maxItems);

        for (int i = 0; i < puckCount; i++)
        {
            float randType = Random.value;
            if (randType < movingChance)
            {
                Instantiate(movingPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity);
            }
            else if (randType < movingChance + explodingChance)
            {
                Instantiate(explodingPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity);
            }
            else
            {
                Instantiate(basicPuck, transform.position + new Vector3(randType / 10, randType / 10, 0), Quaternion.identity);
            }
        }

        waitTime  = 1;
        startTime = Time.time;
        _curState = UFOState.Dropping;
    }
示例#4
0
    private void UpdateCircleAndShootState()
    {
        if (Vector3.Distance(this.transform.position, player.transform.position) > movingDistance + 5)
        {
            state = UFOState.MoveTowards;
        }

        CircleAroundPlayer();
    }
示例#5
0
    void SpawnUFO()
    {
        Instantiationtimer -= Time.deltaTime;

        if (Instantiationtimer <= 0)
        {
            //Step 1: assign the new ufo created below to the spawnedUFO variable
            spawnedUFO         = Instantiate(uFo, new Vector3(-0, -0, -11), Quaternion.identity);
            Instantiationtimer = 5f;
            state = UFOState.Waiting;
        }
    }
示例#6
0
        public IEnumerator MoveToSpace()
        {
            CurrentState = UFOState.MoveToSpace;

            StopHunting();

            while (transform.position != StartPosition)
            {
                transform.position = Vector3.MoveTowards(transform.position, StartPosition, Speed * Time.deltaTime);
                yield return(new WaitForEndOfFrame());
            }
            CurrentState = UFOState.InSpace;
            Audio.Stop();
        }
示例#7
0
    //Use this for initialization
    void Start()
    {
        if (Random.value > 0.5)
        {
            rotationDirection = 1;
        }
        else
        {
            rotationDirection = -1;
        }

        state  = UFOState.MoveTowards;
        player = GameObject.FindGameObjectWithTag("Player");
    }
示例#8
0
        public IEnumerator MoveToPoint(Vector3 point)
        {
            CurrentState = UFOState.MoveToIsland;
            Audio.clip   = IdleSound;
            Audio.volume = 0.75f;
            Audio.Play();

            while (transform.position != point)
            {
                transform.position = Vector3.MoveTowards(transform.position, point, Speed * Time.deltaTime);
                yield return(new WaitForEndOfFrame());
            }

            CurrentState = UFOState.OnIsland;
            CheckCurrentTerrain();
            OnMovedToIsland();
        }
示例#9
0
    // Update is called once per frame
    void Update()
    {
        if (state == UFOState.Spawning)
        {
            SpawnUFO();
        }
        else if (state == UFOState.Waiting)
        {
            //step 2: check if the spawnedUFO variable is empty, using a null check
            if (spawnedUFO == null)
            {
                state = UFOState.Spawning;
            }


            //step 3: if the spawnedUFO variable is empty, change the UFO state to spawning
        }
    }
示例#10
0
    void moveToDropPoint()
    {
        ufoTrail.enabled = false;

        GetComponent <AudioSource>().PlayOneShot(ufoSound);

        int dropPoint = Random.Range(0, dropPoints.Count - 1);

        startPoint = Random.Range(0, startPoints.Count - 1);

        transform.position = startPoints[startPoint].position;
        targetPos          = dropPoints[dropPoint].position;

        ufoTrail.enabled = true;

        entering = true;

        _curState = UFOState.MovingToDrop;
    }
示例#11
0
    private void UpdateMoveState()
    {
        if (player && Vector3.Distance(this.transform.position, player.transform.position) <= Random.Range(movingDistance - 5, movingDistance + 5))
        {
            state = UFOState.CircleAndShoot;

            //determine rotation direction
            if (Random.value > 0.5)
            {
                rotationDirection *= -1;
            }

            //stop approach
            GetComponent <Rigidbody>().drag = 1000;
            //rotationSpeed *= 2;
        }

        MoveToPlayer();
    }
示例#12
0
    void move()
    {
        float step = moveSpeed * Time.deltaTime;

        transform.position = Vector2.MoveTowards(transform.position, targetPos, step);
        float distance = Vector2.Distance(transform.position, targetPos);

        if (distance < 1)
        {
            if (entering)
            {
                entering = false;
                dropPucks();
            }
            else
            {
                entering  = true;
                waitTime  = Random.Range(minWaitTime, maxWaitTime);
                _curState = UFOState.Idle;
            }
        }
    }
示例#13
0
    void leaveDropPoint()
    {
        switch (startPoint)
        {
        case 0:
            targetPos = startPoints[2].position;
            break;

        case 1:
            targetPos = startPoints[3].position;
            break;

        case 2:
            targetPos = startPoints[0].position;
            break;

        case 3:
            targetPos = startPoints[1].position;
            break;
        }

        entering  = false;
        _curState = UFOState.MovingToIdle;
    }
示例#14
0
 void Awake()
 {
     StartPosition = transform.position;
     CurrentState  = UFOState.InSpace;
 }
示例#15
0
 private void OnBecameInvisible()
 {
     state = UFOState.Stop;
 }
示例#16
0
 private void OnBecameVisible()
 {
     state = UFOState.Moving;
 }