Ejemplo n.º 1
0
    void Update()
    {
        if (!dead)
        {
            // See if it's time to shoot
            if (timeSinceLastShot >= nextShotTime)
            {
                Instantiate(bullet, transform.position, Quaternion.identity);
                nextShotTime      = Random.Range(minShotTime, maxShotTime);
                timeSinceLastShot = 0.0f;
            }
            else
            {
                timeSinceLastShot += Time.deltaTime;
            }

            // Get zSpeed based on distance from player
            float zSpeed = MyMath.Map(
                Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position, transform.position),
                0f, 500f, zSpeedMin, zSpeedMax
                );

            Vector3 newPos = new Vector3(
                MyMath.Map(Mathf.PerlinNoise(noiseTime + noiseOffset, 0f), 0f, 1f, -gm.moveRangeX, gm.moveRangeX),
                MyMath.Map(Mathf.PerlinNoise(0f, noiseTime + noiseOffset), 0f, 1f, -gm.moveRangeY, gm.moveRangeY),
                transform.position.z - zSpeed * Time.deltaTime
                );

            rb.MovePosition(newPos);

            noiseTime += noiseSpeed;
        }

        // If dead...
        else
        {
            gm.BounceMe(transform);
        }

        // Destroy me if I leave the screen
        if (transform.position.z < -25f || transform.position.y < -25f)
        {
            gm.bouncingBoys--;
            Destroy(gameObject);
        }

        // See if I was picked up
        if (transform.parent != null)
        {
            rb.isKinematic = true;
        }
    }