コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if (!fire)
            {
                energyController.AddConsumption(0.2f);
                fire             = true;
                audioSource.clip = audioClipIdle;
                audioSource.Play();
            }

            animator.SetBool("Fire", true);
        }
        else
        {
            if (fire)
            {
                energyController.RemoveConsumption(0.2f);
                fire             = false;
                audioSource.clip = audioClipFire;
                audioSource.Play();
            }
            animator.SetBool("Fire", false);
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            turned = !turned;
            if (turned)
            {
                energyController.AddConsumption(0.2f);
            }
            else
            {
                energyController.RemoveConsumption(0.2f);
            }

            light.SetActive(turned);
        }
    }
コード例 #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

        if (move.x > 0)
        {
            if (move.y > 0)
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 135);
            }
            else if (move.y < 0)
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 45);
            }
            else
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 90);
            }
        }
        else if (move.x < 0)

        {
            if (move.y > 0)
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 225);
            }
            else if (move.y < 0)
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 315);
            }
            else
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 270);
            }
        }
        else
        {
            if (move.y > 0)
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 180);
            }
            else
            {
                legs.transform.eulerAngles = new Vector3(0, 0, 0);
            }
        }

        if (move.x != 0 || move.y != 0)
        {
            if (!walk)
            {
                walk = true;
            }
            animator.SetBool("Walk", true);
            animatorLegs.SetBool("Walk", true);
        }
        else
        {
            if (walk)
            {
                walk = false;
            }
            animatorLegs.SetBool("Walk", false);
            animator.SetBool("Walk", false);
        }

        if (Input.GetKey(KeyCode.LeftShift) && (move.x != 0 || move.y != 0))
        {
            if (!running)
            {
                energyController.AddConsumption(0.2f);
                animator.speed     = 3;
                animatorLegs.speed = 3;
            }
            running = true;
        }
        else
        {
            if (running)
            {
                animator.speed     = 2;
                animatorLegs.speed = 2;

                energyController.RemoveConsumption(0.2f);
            }
            running = false;
        }

        if (!running)
        {
            transform.position += move * speed * Time.deltaTime;
        }
        else
        {
            transform.position += move * runSpeed * Time.deltaTime;
        }

        if (walk || running)
        {
            audioSource.mute = false;


            if (!audioSource.isPlaying || (!running && audioSource.clip == runningClip) || (running && audioSource.clip != runningClip))
            {
                if (!running)
                {
                    audioSource.clip = listIfClips[r.Next(listIfClips.Count)];
                }
                else
                {
                    audioSource.clip = runningClip;
                }
                audioSource.Play();
            }
        }
        else
        if (audioSource.isPlaying)
        {
            audioSource.mute = true;
        }


        //Vector3 v3 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //float x0 = transform.position.x;
        //float y0 = transform.position.y;


        //float x1 = v3.x;
        //float y1 = v3.y;

        //float dist = Mathf.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));

        //float angle = Mathf.Abs(Mathf.Atan((y1 - y0) / (x1 - x0)) * (180 / Mathf.PI));


        //if (x1 > x0)
        //{
        //    if (y1 > y0)
        //        realAngle = angle;
        //    else realAngle = 360 - angle;
        //}
        //else
        //{
        //    if (y1 > y0)
        //        realAngle = 180 - angle;
        //    else
        //        realAngle = 180 + angle;
        //}
        //transform.eulerAngles = new Vector3(0, 0, realAngle + 90);
    }