Esempio n. 1
0
    void Spawn()
    {
        if (!hasMole)
        {
            //int num = Random.Range(0, moles.Length);
            int num = CalculateRarity();

            mole = Instantiate(moles[num], transform.position, Quaternion.identity) as GameObject;
            MoleBehavior moleB = mole.GetComponent <MoleBehavior>();
            moleB.myParent = this.gameObject;
            moleB.score    = moleB.score * GameManager.curLevel;
            hasMole        = true;
        }

        Invoke("Spawn", Random.Range(3f, 7f));;
    }
Esempio n. 2
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.tag == "Mole")
                {
                    Instantiate(fx_Punch, hit.point, Quaternion.identity);

                    MoleBehavior mole = hit.collider.gameObject.GetComponent <MoleBehavior>();
                    mole.SwitchCollider(0);
                    mole.anim.SetTrigger("hit");
                    //Debug.Log(hit.collider.gameObject + " got hit");
                }
            }
        }
    }
Esempio n. 3
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))                                 //0:left mouse button, 1:right mouse button 2:middle
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //creat ray
            //Ray ScreenPointToRay(Vector3 position) : Return a ray going from camera through a screen point.
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))//physics check
            {
                if (hit.collider.tag == "Mole")
                {
                    MoleBehavior mole = hit.collider.gameObject.GetComponent <MoleBehavior>();
                    //get the MoleBehavior from the Mole, that i hit

                    mole.SwitchCollider(0);      //turning off

                    mole.anim.SetTrigger("hit"); //using Trigger for calling animation

                    //Debug.Log(hit.collider.gameObject + " got hit ");//check what we hit Mole
                }
            }
        }
    }