Beispiel #1
0
 void Start()
 {
     laserLine = GetComponent <LineRenderer>();
     NiuBi.SetActive(false);
     Gun.SetActive(true);
     GunType.text = "Hand Gun";
 }
Beispiel #2
0
    void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            //Debug.Log("hello");
            if (Gun.activeSelf)
            {
                Gun.SetActive(false);
                NiuBi.SetActive(true);
            }
            else
            {
                Gun.SetActive(true);
                NiuBi.SetActive(false);
            }
            //Gun.SetActive(true);
            //NiuBi.SetActive(false);
        }

        if (Input.GetKeyDown("space"))
        {
            if (Gun.activeSelf)
            {
                RaycastHit Shot;
                if (Physics.Raycast(Gun.transform.position, transform.TransformDirection(Vector3.forward), out Shot, GunAllowedRange))
                {
                    Shot.transform.SendMessage("DeductPoints", GunDamageAmount, SendMessageOptions.DontRequireReceiver);
                }
            }

            if (NiuBi.activeSelf)
            {
                if (bullets > 0)
                {
                    bullets -= 1;
                    RaycastHit[] Shot = Physics.RaycastAll(NiuBi.transform.position, transform.TransformDirection(Vector3.forward), NiuBiAllowedRange);
                    if (Shot.Length != 0)
                    {
                        for (int i = 0; i < Shot.Length; i++)
                        {
                            Shot[i].collider.SendMessage("DeductPoints", NiuBiDamageAmount, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                }
            }
        }
    }
Beispiel #3
0
    void Update()
    {
        if (laserLine.enabled)
        {
            keep_time -= Time.deltaTime;
            if (keep_time <= 0)
            {
                laserLine.enabled = false;
                keep_time         = 0.1f;
            }
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
            if (Gun.activeSelf)
            {
                Gun.SetActive(false);
                NiuBi.SetActive(true);
                GunType.text = "Laser";
            }
            else
            {
                Gun.SetActive(true);
                NiuBi.SetActive(false);
                GunType.text = "Hand Gun";
            }
        }

        if (Input.GetKeyDown("space") && cold_time <= 0)
        {
            if (Gun.activeSelf)
            {
                AudioSource.PlayClipAtPoint(AC1, transform.localPosition);
                RaycastHit Shot;
                if (Physics.Raycast(Gun.transform.position, transform.TransformDirection(Vector3.forward), out Shot, GunAllowedRange))
                {
                    Shot.transform.SendMessage("DeductPoints", GunDamageAmount, SendMessageOptions.DontRequireReceiver);
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, Shot.point);
                    laserLine.enabled = true;
                }
                else
                {
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, transform.forward * 200 + transform.position);
                    laserLine.enabled = true;
                }
            }

            if (NiuBi.activeSelf)
            {
                if (bullets > 0)
                {
                    AudioSource.PlayClipAtPoint(AC4, transform.localPosition);
                    bullets -= 1;
                    RaycastHit[] Shot = Physics.RaycastAll(NiuBi.transform.position, transform.TransformDirection(Vector3.forward), NiuBiAllowedRange);
                    if (Shot.Length != 0)
                    {
                        for (int i = 0; i < Shot.Length; i++)
                        {
                            Shot [i].collider.SendMessage("DeductPoints", NiuBiDamageAmount, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, transform.forward * 200 + transform.position);
                    laserLine.enabled = true;
                }
                else
                {
                    AudioSource.PlayClipAtPoint(AC5, transform.localPosition);
                }
            }
            cold_time = 0.5f;
        }
        else
        {
            cold_time -= Time.deltaTime;
        }
    }
Beispiel #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
//		Vector3 moveVec = new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"), 0, CrossPlatformInputManager.GetAxis ("Vertical")) * moveForce;
//		mybody.AddForce (moveVec);
        {
            float   moveHorizontal = -CrossPlatformInputManager.GetAxis("Vertical");
            float   moveVertical   = CrossPlatformInputManager.GetAxis("Horizontal");
            Vector3 movement       = new Vector3(moveHorizontal, 0.0f, moveVertical).normalized;
            float   angle_Y        = Mathf.Asin(moveHorizontal / Mathf.Sqrt(Mathf.Pow(moveHorizontal, 2) + Mathf.Pow(moveVertical, 2)));
            if (moveVertical < 0)
            {
                if (moveHorizontal > 0)
                {
                    angle_Y = Mathf.PI - angle_Y;
                }
                else
                {
                    angle_Y = -Mathf.PI - angle_Y;
                }
            }
            if (moveHorizontal != 0 || moveVertical != 0)
            {
                transform.localEulerAngles = new Vector3(0.0f, (180 / Mathf.PI) * angle_Y, 0.0f);
            }
            transform.position += movement * Time.deltaTime * 10;
        }

        if (laserLine.enabled)
        {
            keep_time -= Time.deltaTime;
            if (keep_time <= 0)
            {
                laserLine.enabled = false;
                keep_time         = 0.1f;
            }
        }


        if (CrossPlatformInputManager.GetButton("Change"))
        {
            Debug.Log("hello");
            if (Gun.activeSelf)
            {
                Gun.SetActive(false);
                NiuBi.SetActive(true);
                GunType.text = "Laser";
            }
            else
            {
                Gun.SetActive(true);
                NiuBi.SetActive(false);
                GunType.text = "Hand Gun";
            }
            //Gun.SetActive(true);
            //NiuBi.SetActive(false);
        }

        if (CrossPlatformInputManager.GetButton("Shoot") && cold_time <= 0)
        {
            if (Gun.activeSelf)
            {
                AudioSource.PlayClipAtPoint(AC1, transform.localPosition);
                RaycastHit Shot;
                if (Physics.Raycast(Gun.transform.position, transform.TransformDirection(Vector3.forward), out Shot, GunAllowedRange))
                {
                    Shot.transform.SendMessage("DeductPoints", GunDamageAmount, SendMessageOptions.DontRequireReceiver);
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, Shot.point);
                    laserLine.enabled = true;
                }
                else
                {
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, transform.forward * 200 + transform.position);
                    laserLine.enabled = true;
                }
            }

            if (NiuBi.activeSelf)
            {
                //else{
                if (PlayerShooting.bullets > 0)
                {
                    AudioSource.PlayClipAtPoint(AC4, transform.localPosition);
                    PlayerShooting.bullets -= 1;
                    RaycastHit[] Shot = Physics.RaycastAll(NiuBi.transform.position, transform.TransformDirection(Vector3.forward), NiuBiAllowedRange);
                    if (Shot.Length != 0)
                    {
                        for (int i = 0; i < Shot.Length; i++)
                        {
                            Shot [i].collider.SendMessage("DeductPoints", NiuBiDamageAmount, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    laserLine.SetPosition(0, transform.position);
                    laserLine.SetPosition(1, transform.forward * 200 + transform.position);
                    laserLine.enabled = true;
                }
                else
                {
                    AudioSource.PlayClipAtPoint(AC5, transform.localPosition);
                }
            }
            cold_time = 0.5f;
        }
        else
        {
            cold_time -= Time.deltaTime;
        }
    }
Beispiel #5
0
 void Start()
 {
     laserLine = GetComponent <LineRenderer>();
     NiuBi.SetActive(false);
     Gun.SetActive(true);
 }
Beispiel #6
0
 void Start()
 {
     NiuBi.SetActive(false);
     Gun.SetActive(true);
 }