Exemple #1
0
    void attack()
    {
        if (selectedScript != null && selected != null) {
            if (Input.GetMouseButtonDown(0) && selectedScript.hasAttacked == false && t != Time.frameCount) {
                Ray ray2 = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray2.origin, ray2.direction, out hit, 300, unitlayers)) {
                    Debug.Log("Attacking!");

                    isAttacking = true;
                    Target = hit.collider.gameObject;
                    targetScript = Target.GetComponent<Stats>();
                    selectedScript.hit();
                    if (targetScript.isAttacked()) {
                        selectedScript.hasMoved = true;

                        //edited by duwei
                        anim = selected.GetComponent<Animator>();
                        if (anim != null) {
                            anim.SetInteger("IsAtt", 1);
                            anim.SetInteger("IsAtt", 0);
                        }

                        //edited by duwei 1 line
                        Position = selected.transform.position + new Vector3(0, 0, 1);

                        resetSelected();
                    } else {
                        selectedScript.hasAttacked = false;
                    }

                }
            }
        }
    }