Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 vecAP = player.transform.position - transform.position;

        if (vecAP.magnitude < 50.0f)
        {
            if (bulletimer > 1.0f)
            {
                bulletimer = 0.0f;
                Vector3 spawnPos = gameObject.transform.position;
                spawnPos.x += 0.0f;
                spawnPos.z += 0.0f;
                spawnPos.y  = 10.0f;

                GameObject   obj = Instantiate(bullet, spawnPos, Quaternion.identity) as GameObject;
                AppleBullets b   = obj.GetComponent <AppleBullets>();

                b.thrust.x = 100.0f * vecAP[0];
                b.thrust.z = 100.0f * vecAP[2];
                b.thrust.y = 100.0f * (player.transform.position[1] - 10.0f);
            }
        }
        bulletimer = bulletimer + 0.01f;
    }
Beispiel #2
0
    void Update()
    {
        if ((timer > 30.0f) && (timer < 45.0f))
        {
            if (bullettimer > 1.0f)
            {
                bullettimer = 0.0f;
                Vector3 spawnPos = gameObject.transform.position;
                spawnPos.x += 0.0f;
                spawnPos.z += 0.0f;
                spawnPos.y  = 1.9f;

                GameObject   obj = Instantiate(bullet, spawnPos, Quaternion.identity) as GameObject;
                AppleBullets b   = obj.GetComponent <AppleBullets>();

                Vector3 vecAP = player.transform.position - transform.position;
                vecAP.y  = -1.5f;
                b.thrust = 100.0f * vecAP;
            }
            bullettimer = bullettimer + 0.003f;
        }



        float           vel = rigidbody.velocity.magnitude;
        ParticleEmitter pe  = gameObject.GetComponentInChildren <ParticleEmitter>();

        if (vel < 0.1)
        {
            pe.emit = false;
            if (!idleSet)
            {
                idleSet = true;
                int r = UnityEngine.Random.Range(1, 6);
                if (r == 1)
                {
                    idleAnimation = "look";
                }
                if (r == 2)
                {
                    idleAnimation = "kick";
                }
                if (r == 3)
                {
                    idleAnimation = "handstand";
                }
                if (r == 4)
                {
                    idleAnimation = "dance";
                }
                if (r == 5)
                {
                    idleAnimation = "jump";
                }
            }
            animation.CrossFade(idleAnimation);
        }
        if (vel > 0.1 && vel < 2)
        {
            pe.emit        = true;
            pe.maxEmission = 10;
            animation.CrossFade("walk");
            idleSet = false;

            gameObject.GetComponentInChildren <ParticleEmitter>().emit        = true;
            gameObject.GetComponentInChildren <ParticleEmitter>().maxEmission = 10;
        }
        if (vel >= 2)
        {
            pe.emit                = true;
            pe.maxEmission         = 20;
            animation["run"].speed = 0.8f;
            animation.CrossFade("run");
            idleSet = false;


            gameObject.GetComponentInChildren <ParticleEmitter>().emit        = true;
            gameObject.GetComponentInChildren <ParticleEmitter>().maxEmission = 20;
        }
    }