Exemplo n.º 1
0
    // if not stunned then move the enemy when time is > _moveTime
    void Update()
    {
        if (!isStunned)
        {
            if (Time.time >= _moveTime)
            {
                EnemyMovement();
            }
            else
            {
                _animator.SetBool("Moving", false);
            }
        }

        // Check to see if character is grounded by raycasting from the middle of the player
        // down to the groundCheck position and see if collected with gameobjects on the
        // whatIsGround layer
        _isGrounded = Physics2D.Linecast(_transform.position, groundCheck.position, whatIsGround);

        // if on ground, ensure waypoints move along ground
        if (_isGrounded)
        {
            if (myWaypoints == null || myWaypoints.Length == 0 && prefabMovingEnemy != null)
            {
                myWaypoints = new GameObject[2];

                GameObject movingEnemy = Object.Instantiate(prefabMovingEnemy, transform.position, Quaternion.identity);

                int i = 0;
                foreach (Transform child in movingEnemy.transform)
                {
                    if (child.CompareTag("Enemy"))
                    {
                        Destroy(child.gameObject);
                    }
                    else if (child.CompareTag("Waypoint"))
                    {
                        myWaypoints[i] = child.gameObject;
                        i++;
                    }
                }
                this.transform.SetParent(movingEnemy.transform);

                //GameObject wayPoint2 = Object.Instantiate(prefabWaypoint, transform.position, Quaternion.identity);

                //myWaypoints = new GameObject[] { wayPoint1, wayPoint2 };
            }

            if (myWaypoints.Length > 1)
            {
                Vector3 groundLeft  = new Vector3(ScreenUtils.GetCameraLeftEdge(Camera.main) + 1, -1.982f, 0f);
                Vector3 groundRight = new Vector3(ScreenUtils.GetCameraRightEdge(Camera.main) - 1, -1.982f, 0f);

                myWaypoints[0].transform.position = groundLeft;
                myWaypoints[1].transform.position = groundRight;
            }
        }
    }
Exemplo n.º 2
0
    // Use this for initialization
    protected virtual void Start()
    {
        foreach (Camera c in Camera.allCameras)
        {
            if (c.CompareTag("BackgroundCamera"))
            {
                this.currentCamera = c;

                this.screenWidth = ScreenUtils.GetCameraRightEdge(this.currentCamera) - ScreenUtils.GetCameraLeftEdge(this.currentCamera);

                break;
            }
        }

        this.halfWidth = this.gameObject.GetComponent <BoxCollider2D>().size.x / 2;
    }
Exemplo n.º 3
0
    private void createNewPlatform(float platformY)
    {
        // platform must be created off screen right
        float platformX = ScreenUtils.GetCameraRightEdge(Camera.main);

        // randomly picked a platform length from 1-3
        int platformCount = Random.Range(1, 4);

        int chanceOfMovingPlatform = Random.Range(0, 10);

        if (chanceOfMovingPlatform > 5)
        {
            SceneBuilder.CreateMovingPlatform(prefebMovingPlatform, prefebCoin, prefebEnemy, new Vector3(platformX, platformY, 0f));
        }
        else
        {
            SceneBuilder.CreatePlatform(prefabPlatform, prefebCoin, prefebEnemy, prefebMovingEnemy, new Vector3(platformX, platformY, 0f), platformCount);
        }
    }
Exemplo n.º 4
0
 protected override bool ExitScreenRight()
 {
     return(transform.position.x > ScreenUtils.GetCameraRightEdge(Camera.main));
 }
Exemplo n.º 5
0
 protected override float GetNewRightX(float currentX)
 {
     return(ScreenUtils.GetCameraRightEdge(Camera.main));
 }
Exemplo n.º 6
0
    protected virtual bool ExitScreenRight()
    {
        float leftEdge = transform.position.x - halfWidth;

        return(leftEdge > ScreenUtils.GetCameraRightEdge(this.currentCamera));
    }