Example #1
0
	void die(){
		if (divisions > 0){
			float bulletAngle = Mathf.Atan2(speed.y, speed.x) * Mathf.Rad2Deg + 90f/2f;

			for (int i=0; i < 2; i++){
				GameObject bubble;
				bubble = Instantiate(bubblePrefab, transform.position, Quaternion.identity) as GameObject;

				bubbleScript bscr = bubble.GetComponent<bubbleScript>();
				bscr.SetBubbleType(managerScript.man.currentBubble);
				bscr.divisions = divisions - 1;
				bscr.size = size;
				if (size > 1){
					bscr.size--;
				}
				bscr.updateSize();

				float spread = Random.Range(-bubbleType.spread, bubbleType.spread);

				bscr.speed = new Vector3(Mathf.Cos((bulletAngle + spread)*Mathf.Deg2Rad), Mathf.Sin((bulletAngle + spread)*Mathf.Deg2Rad), 0f) * bubbleType.speed;

				bulletAngle -= 90f;
			}
		}

		Instantiate(bubblePopPrefab, transform.position, Quaternion.identity);
		Destroy(gameObject);
	}
    public void controlChar()
    {
        if (Input.GetKey("d"))
        {
            if (!Input.GetKey("a"))
            {
                move(1, 0);
            }
        }
        if (Input.GetKey("a"))
        {
            if (!Input.GetKey("d"))
            {
                move(-1, 0);
            }
        }
        if (Input.GetKey("s"))
        {
            if (!Input.GetKey("w"))
            {
                move(0, 1);
            }
        }
        if (Input.GetKey("w"))
        {
            if (!Input.GetKey("s"))
            {
                move(0, -1);
            }
        }
        if (!Input.GetKey("w") && !Input.GetKey("s") && !Input.GetKey("a") && !Input.GetKey("d"))
        {
            if (bodyState.IsName("walk"))
            {
                anim.Play("idle");
            }
        }

        if (Input.GetKey("w") && Input.GetKey("s"))
        {
            speed.y = 0;
            if (bodyState.IsName("walk"))
            {
                anim.Play("idle");
            }
        }
        if (Input.GetKey("a") && Input.GetKey("d"))
        {
            speed.x = 0;
            if (bodyState.IsName("walk"))
            {
                anim.Play("idle");
            }
        }

        if (Input.GetMouseButton(1))
        {
            anim.Play("head_mouth_open");

            var em = absorbEffect.emission;
            em.enabled = true;
        }
        else
        {
            var em = absorbEffect.emission;
            em.enabled = false;

            if (Input.GetMouseButton(0))
            {
                anim.Play("head_mouth_open");

                if (cooldown == 0)
                {
                    managerScript.Bubble bubbleType = managerScript.man.bubbleDict[managerScript.man.currentBubble];
                    cooldown = bubbleType.cooldown;

                    float bulletAngle = headAngle + (bubbleType.number * 15f - 15f) / 2f;

                    for (int i = 0; i < bubbleType.number; i++)
                    {
                        Vector3 bubbleVector = new Vector3(Mathf.Cos(bulletAngle * Mathf.Deg2Rad), Mathf.Sin(bulletAngle * Mathf.Deg2Rad), 0f);

                        GameObject bubble;
                        bubble = Instantiate(bubblePrefab, axolotlHead.transform.position + bubbleVector * 1f, Quaternion.identity) as GameObject;

                        bubbleScript bscr = bubble.GetComponent <bubbleScript>();
                        bscr.SetBubbleType(managerScript.man.currentBubble);

                        float spread = Random.Range(-bubbleType.spread, bubbleType.spread);

                        bscr.speed = new Vector3(Mathf.Cos((bulletAngle + spread) * Mathf.Deg2Rad), Mathf.Sin((bulletAngle + spread) * Mathf.Deg2Rad), 0f) * bubbleType.speed;

                        bulletAngle -= 15f;
                    }
                }
            }
        }


        /*
         * if (Input.GetKeyDown("z")){
         *      attack();
         * }
         */

        if (!Input.GetKey("a") && !Input.GetKey("d"))
        {
            speed.x = 0;
        }

        if (!Input.GetKey("w") && !Input.GetKey("s"))
        {
            speed.y = 0;
        }
    }