Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        base.Init();
        //Build a list of directions.
        Direction.Dir[] dirs = new Direction.Dir[4];
        dirs[0] = Direction.Dir.UP;
        dirs[1] = Direction.Dir.DOWN;
        dirs[2] = Direction.Dir.LEFT;
        dirs[3] = Direction.Dir.RIGHT;

        isAlive = true;

        //This gives us a random direction
        dir = dirs[Random.Range(0, dirs.Length)];

        //Get the extents
        top    = CollectorGameManager.GetInstance().topExtent;
        bottom = CollectorGameManager.GetInstance().bottomExtent;
        left   = CollectorGameManager.GetInstance().leftExtent;
        right  = CollectorGameManager.GetInstance().rightExtent;

        //Decide start pos and movement.
        float x = Random.Range(left.position.x, right.position.x);
        float y = Random.Range(bottom.position.y, top.position.y);

        switch (dir)
        {
        case Direction.Dir.UP:
        {
            y = bottom.position.y;
            break;
        }

        case Direction.Dir.DOWN:
        {
            y = top.position.y;
            break;
        }

        case Direction.Dir.LEFT:
        {
            x = right.position.x;
            break;
        }

        case Direction.Dir.RIGHT:
        {
            x = left.position.x;
            break;
        }

        default:
        {
            y = bottom.position.y;     //up by default.
            break;
        }
        }
        transform.position = new Vector2(x, y);
        SetMovement(Direction.DirToVec2(dir));
    }
Example #2
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         Destroy(gameObject);
         Destroy(col.gameObject);
         CollectorGameManager.GetInstance().GameOver();
     }
 }
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         CollectorGameManager.GetInstance().AddScore(scoreValue);
         Instantiate(coinPrefab);
         Destroy(gameObject);
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        Transform top    = CollectorGameManager.GetInstance().topExtent;
        Transform bottom = CollectorGameManager.GetInstance().bottomExtent;
        Transform left   = CollectorGameManager.GetInstance().leftExtent;
        Transform right  = CollectorGameManager.GetInstance().rightExtent;

        float x = Random.Range(left.position.x, right.position.x);
        float y = Random.Range(bottom.position.y, top.position.y);

        transform.position = new Vector2(x, y);
    }
 /// <summary>
 /// Start the Mangas game object.
 /// </summary>
 void Start()
 {
     mangasRB2d  = GetComponent <Rigidbody2D> ();
     gameManager = Camera.main.GetComponent <CollectorGameManager> ();
 }