Пример #1
0
    void OnGUI()
    {
        int size=Screen.height/10;
        if (GUI.Button(new Rect(Screen.width/2+2*Screen.width/5-size/2,Screen.height/2+Screen.height/6-size/2,Screen.height/10,Screen.height/10),btn_shoot,"label"))
        {
        Ray ray = Camera.main.ScreenPointToRay( new Vector3(Screen.width/2,Screen.height/2,0) );
        RaycastHit hit;
        Instantiate(flash,gun.transform.position,gun.transform.rotation);
        if( Physics.Raycast( ray, out hit, 10000 ) )
                {
               	print( hit.transform.gameObject.name );
                }

        if(hit.transform.gameObject.name == "doctor(Clone)"||hit.transform.gameObject.name == "doc1(Clone)")
                {
                Instantiate(blood,hit.point,Quaternion.identity);
                attack = hit.transform.gameObject.GetComponent("Ghost_Attack") as Ghost_Attack;
                attack.damage();
                }
        else if(hit.transform.gameObject.name != "doctor(Clone)"&&hit.transform.gameObject.name != "doc1(Clone)")
                {
                Instantiate(miss,hit.point,Quaternion.identity);
                }

        }
    }
Пример #2
0
    void OnGUI()
    {
        /*
        int i = 0;
        while (i < Input.touchCount) {
        if(btn_shoot.guiTexture.HitTest(Input.GetTouch(i).position))
        {
        if(a==true)
        {
        Ray ray = Camera.main.ScreenPointToRay( new Vector3(Screen.width/2,Screen.height/2,0) );
        RaycastHit hit;
        Instantiate(flash,gun.transform.position,gun.transform.rotation);
        if( Physics.Raycast( ray, out hit, 10000 ) )
                {
               	print( hit.transform.gameObject.name );
                }

        if(hit.transform.gameObject.name == "doctor(Clone)"||hit.transform.gameObject.name == "doc1(Clone)")
                {
                Instantiate(blood,hit.point,Quaternion.identity);
                attack = hit.transform.gameObject.GetComponent("Ghost_Attack") as Ghost_Attack;
                attack.damage();
                }
        else if(hit.transform.gameObject.name != "doctor(Clone)"&&hit.transform.gameObject.name != "doc1(Clone)")
                {
                Instantiate(miss,hit.point,Quaternion.identity);
                }
        b=Time.timeSinceLevelLoad;
        a=false;
        }
        }
        ++i;
        }
        reload();	*/

        int i = 0;
        while (i < Input.touchCount) {
        if (Input.GetTouch(i).phase == TouchPhase.Began) {

        if(btn_shoot.guiTexture.HitTest(Input.GetTouch(i).position))
        {
        //	audio.clip=shoot;
        //audio.PlayOneShot(shoot);
        audio.Play();
        Ray ray = Camera.main.ScreenPointToRay( new Vector3(Screen.width/2,Screen.height/2,0) );
        RaycastHit hit;
        Instantiate(flash,gun.transform.position,gun.transform.rotation);
        if( Physics.Raycast( ray, out hit, 10000 ) )
                {
               	//print( hit.transform.gameObject.name );doctor_mist

                }

        if(hit.transform.gameObject.name == "doctor(Clone)"||hit.transform.gameObject.name == "doc1(Clone)"||hit.transform.gameObject.name == "doctor_mist(Clone)")
                {
                Instantiate(blood,hit.point,Quaternion.identity);
                attack = hit.transform.gameObject.GetComponent("Ghost_Attack") as Ghost_Attack;
                attack.damage();
                }
        else if(hit.transform.gameObject.name != "doctor(Clone)"&&hit.transform.gameObject.name != "doc1(Clone)"||hit.transform.gameObject.name != "doctor_mist(Clone)")
                {
                Instantiate(miss,hit.point,Quaternion.identity);
                }
            }
            }
            ++i;
        }
    }