Beispiel #1
0
    void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            //Cuento el tiempo que mantuve presionada la tecla
            pressedTime += Time.deltaTime;
        }

        if (Input.GetButtonUp("Fire1"))
        {
            //Instancio la bala y obtengo su componente de movimiento para modificar la velocidad
            GameObject       go    = Instantiate(prefab, transform.position, transform.rotation);
            ConstantMovement goMov = go.GetComponent <ConstantMovement> ();

            //Divido el tiempo que mantuve presionada la tecla del maximo tiempo para
            //obtener el porcentaje que la mantuve presionada (limitado entre 0..1)
            float timePerc = Mathf.Clamp01(pressedTime / maxTime);

            //La velocidad de la bala va a ser entre la minima y la maxima segun
            //cuanto tiempo mantuve presionada la tecla
            goMov.Speed = minSpeed + (maxSpeed - minSpeed) * timePerc;

            //Reseteo el contador de tiempo para la siguiente bala
            pressedTime = 0;
        }
    }
    void Atirar()
    {
        anim.SetBool("Atirando", true);

        GameObject       tiroObject = Instantiate(tiro, spawn.position, Quaternion.identity);
        ConstantMovement cm         = tiroObject.GetComponent <ConstantMovement> ();

        if (transform.eulerAngles.y == 180)
        {
            cm.InverteTiro();
        }

        cooldownTimer = 0;
        tiro.transform.Translate(movement * Time.deltaTime);
    }
Beispiel #3
0
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            //Guardo el momento en el que presione la tecla
            pressStartTime = Time.time;
        }

        if (Input.GetButtonUp("Fire1"))
        {
            //Calculo el tiempo que mantuve presionando comparando la hora actual
            //con la que era cuando presione la tecla
            float pressedTime = Time.time - pressStartTime;

            //Esto se explica en ShooterCharged.cs
            GameObject       go       = Instantiate(prefab, transform.position, transform.rotation);
            ConstantMovement goMov    = go.GetComponent <ConstantMovement> ();
            float            timePerc = Mathf.Clamp01(pressedTime / maxTime);
            goMov.Speed = minSpeed + (maxSpeed - minSpeed) * timePerc;
        }
    }
Beispiel #4
0
        void Update()
        {
            GameObject[] persons = GameObject.FindGameObjectsWithTag("Person");
            foreach (var person in persons)
            {
                person.transform.GetChild(0).gameObject.SetActive(GlobalData.personActives);
            }
            if (!GlobalData.pause)
            {
                if (!allowDiactivation || (allowDiactivation && GlobalData.personActives))
                {
                    if (Time.time > lastCheckedTime + timeBetweenSpawns)
                    {
                        if (minTime < timeBetweenSpawns - timeDecrease)
                        {
                            timeBetweenSpawns -= timeDecrease;
                        }
                        if (minAmount + timeDecrease < spawnerPos.Length - 1)
                        {
                            minAmount += timeDecrease;
                        }

                        int amount = 0;
                        int skip   = 0;
                        int summon = 0;
                        if (prev < 2)
                        {
                            int min = Mathf.FloorToInt(minAmount) > 2 ? Mathf.FloorToInt(minAmount) : 2;
                            amount = GlobalData.rnd.Next(min, spawnerPos.Length);
                        }
                        else if (prev == spawnerPos.Length - 1)
                        {
                            amount = GlobalData.rnd.Next(Mathf.FloorToInt(minAmount), spawnerPos.Length - 1);
                        }
                        else
                        {
                            amount = GlobalData.rnd.Next(Mathf.FloorToInt(minAmount), spawnerPos.Length);
                        }

                        for (int i = 0; i < spawnerPos.Length; i++)
                        {
                            bool spawn = false;
                            if (summon == amount)
                            {
                                // Skip
                                skip++;
                            }
                            else if (amount + skip == spawnerPos.Length)
                            {
                                // Spawn.
                                spawn = true;
                                summon++;
                            }
                            else
                            {
                                // Random.
                                int choise = GlobalData.rnd.Next(0, 2);
                                if (choise == 0)
                                {
                                    skip++;
                                }
                                else if (choise == 1)
                                {
                                    spawn = true;
                                    summon++;
                                }
                            }
                            if (spawn)
                            {
                                float percent = (float)GlobalData.rnd.NextDouble();
                                foreach (var item in prefab)
                                {
                                    if (item.spawnPercent > percent)
                                    {
                                        GameObject obj = Instantiate(item.prefab);
                                        obj.transform.position = spawnerPos[i].position;
                                        if (item.randomColor)
                                        {
                                            Material material = new Material(Shader.Find("Shader Graphs/LandCurvature"));
                                            material.SetFloat("Vector1_6DBD6DBE", 0.0007f);
                                            Color color = new Color();
                                            color.r = (float)GlobalData.rnd.NextDouble();
                                            color.b = (float)GlobalData.rnd.NextDouble();
                                            color.g = (float)GlobalData.rnd.NextDouble();
                                            material.SetColor("Color_85E369DF", color);
                                            obj.GetComponent <SetMaterial>().ChangeMaterial(material);
                                        }
                                        ConstantMovement mov = obj.GetComponent <ConstantMovement>();
                                        if (mov != null && mov.GetModify())
                                        {
                                            prefabMaxSpeed = car.GetSpeed();
                                            float lerp = (float)GlobalData.rnd.NextDouble();
                                            mov.SetSpeed(Mathf.Lerp(10, 20, lerp));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        lastCheckedTime = Time.time;
                        prev            = amount;
                    }
                }
                for (int i = 0; i < dispawnerPos.Length; i++)
                {
                    Collider[] col = Physics.OverlapBox(dispawnerPos[i].position + Vector3.up * 1, new Vector3(2, 2, 2));
                    foreach (var item in col)
                    {
                        if (item.tag == "Enemy" || item.tag == "Person")
                        {
                            GameObject.Destroy(item.gameObject);
                        }
                    }
                }
            }
        }