Exemplo n.º 1
0
    /**
     * Handle the player shoot event.
     */
    void handlePlayerShoot()
    {
        if (Input.GetButtonDown("Shoot") && shotCooldownTimer <= 0f)
        {
            shotCooldownTimer = SHOT_COOLDOWN;
            Vector3[] directions = { transform.up, transform.right, -transform.up, -transform.right };

            for (int i = 0; i < directions.Length; i++)
            {
                Vector2 spawnLocation = transform.position + directions[i] * (0.5f + shotPrefab.transform.localScale.x * 0.5f);
                Debug.DrawRay(spawnLocation, directions[i] * 2f, Color.red);

                GameObject go = ObjectPoolController.InstantiateFromPool(shotPrefab, spawnLocation, transform.rotation);
                go.GetComponent <Rigidbody2D>().velocity = /*new Vector3(rb.velocity.x, rb.velocity.y, 0f) +*/ (directions[i] * 1f);

                if (directions[i] == transform.right || directions[i] == -transform.right)
                {
                    go.transform.Rotate(new Vector3(0f, 0f, 90f));
                }
            }

            shrinkPlayer();
        }
        if (shotCooldownTimer > 0f)
        {
            shotCooldownTimer -= Time.deltaTime;
        }
    }
Exemplo n.º 2
0
    /**
     * START
     */
    void Start()
    {
        rb            = GetComponent <Rigidbody2D>();
        blobFragments = new List <GameObject>();

        Physics2D.IgnoreLayerCollision(blobFragmentLayer, blobFragmentLayer);
        int numberOfFragments = Random.Range(3, 7);

        for (int i = 0; i < numberOfFragments; i++)
        {
            blobFragments.Add(
                ObjectPoolController.InstantiateFromPool(blobFragmentPrefab, transform.position, transform.rotation)
                );
            blobFragments[i].transform.parent = gameObject.transform;
            blobFragments[i].transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
        }

        rb.velocity = Random.insideUnitCircle * moveSpeed;
    }