Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if(type==_AttackCreepType.Attack){
            if(target!=null){
                if(attackMethod==_AttackMethod.Melee){
                    if(attackMode==_AttackMode.StopNAttack){
                        LayerMask mask=1<<LayerManager.LayerTower();
                        if(!Physics.Raycast(unit.thisT.position+new Vector3(0, 1, 0), unit.thisT.forward, meleeAttackRange, mask)){
                            MoveToPoint(target.thisT.position);
                        }
                        else{
                            if(meleeState!=_MeleeState.Attacking){
                                unit.StopAnimation();
                                meleeState=_MeleeState.Attacking;
                                targetInLos=true;
                            }
                        }
                    }
                    else{
                        LayerMask mask=1<<LayerManager.LayerTower();

                        if(Physics.Raycast(unit.thisT.position+new Vector3(0, 1, 0), unit.thisT.forward, meleeAttackRange, mask)){
                            if(meleeState!=_MeleeState.Attacking){
                                //unit.StopAnimation();
                                meleeState=_MeleeState.Attacking;
                                targetInLos=true;
                            }
                        }
                        else{
                            if(meleeState==_MeleeState.Attacking){
                                meleeState=_MeleeState.OutOfRange;
                                targetInLos=false;
                            }
                        }
                    }
                }
                else if(attackMethod==_AttackMethod.Range){
                    if(turretObject!=null){
                        Quaternion wantedRot=Quaternion.LookRotation(target.thisT.position-unit.thisT.position);

                        turretObject.rotation=Quaternion.Slerp(turretObject.rotation, wantedRot, Time.deltaTime*10);

                        if(Quaternion.Angle(wantedRot, turretObject.rotation)<10){
                            targetInLos=true;
                        }
                        else targetInLos=false;

                        if(attackMode==_AttackMode.StopNAttack){
                            Vector3 point=target.thisT.position;
                            point.y=unit.thisT.position.y;
                            wantedRot=Quaternion.LookRotation(point-unit.thisT.position);
                            unit.thisT.rotation=Quaternion.Slerp(unit.thisT.rotation, wantedRot, 10*Time.deltaTime);
                        }
                    }
                    else{
                        if(attackMode==_AttackMode.StopNAttack){
                            Vector3 point=target.thisT.position;
                            point.y=unit.thisT.position.y;
                            Quaternion wantedRot=Quaternion.LookRotation(point-unit.thisT.position);
                            unit.thisT.rotation=Quaternion.Slerp(unit.thisT.rotation, wantedRot, 10*Time.deltaTime);

                            if(Quaternion.Angle(unit.thisT.rotation, wantedRot)<7 && !targetInLos) targetInLos=true;
                            else if(targetInLos) targetInLos=false;
                        }
                        else{
                            if(!targetInLos) targetInLos=true;
                        }
                    }
                }

            }
            else{
                if(targetInLos) targetInLos=true;

                if(attackMethod==_AttackMethod.Melee){

                }
                else if(attackMethod==_AttackMethod.Range){
                    if(turretObject!=null){
                        Quaternion wantedRot=Quaternion.Euler(0, 0, 0);

                        turretObject.localRotation=Quaternion.Slerp(turretObject.localRotation, wantedRot, Time.deltaTime*10);
                    }
                }
            }
        }
        else if(type==_AttackCreepType.Support){
            if(attackMode==_AttackMode.StopNAttack){

            }
            else if(attackMode==_AttackMode.RunNGun){

            }
        }
    }
Пример #2
0
    IEnumerator ScanForTarget()
    {
        LayerMask maskTarget = 1 << LayerManager.LayerTower();

        while (true)
        {
            if (target == null)
            {
                if (unit.HasStoppedMoving())
                {
                    unit.ResumeAnimation();
                    unit.ResumeMoving();
                }

                if (attackStrategicPointOnly)
                {
                    List <Unit> list = GameControl.GetLifeUnit();

                    foreach (Unit targetUnit in list)
                    {
                        if (targetUnit != null && targetUnit.HPAttribute.HP > 0)
                        {
                            if (Vector3.Distance(unit.thisT.position, targetUnit.GetTargetT().position) <= range)
                            {
                                target = targetUnit;

                                if (attackMode == _AttackMode.StopNAttack)
                                {
                                    if (attackMethod != _AttackMethod.Melee)
                                    {
                                        unit.StopAnimation();
                                    }
                                    unit.StopMoving();
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (targetArea == _TargetingA.AllAround)
                    {
                        Collider[] cols = Physics.OverlapSphere(unit.thisT.position, range, maskTarget);
                        //if(cols!=null && cols.Length>0) Debug.Log(cols[0]);

                        if (cols.Length > 0)
                        {
                            Collider currentCollider = cols[Random.Range(0, cols.Length)];
                            Unit     targetTemp      = currentCollider.gameObject.GetComponent <Unit>();
                            if (targetTemp != null && targetTemp.HPAttribute.HP > 0)
                            {
                                target = targetTemp;

                                if (attackMode == _AttackMode.StopNAttack)
                                {
                                    if (attackMethod != _AttackMethod.Melee)
                                    {
                                        unit.StopAnimation();
                                    }
                                    unit.StopMoving();
                                    //if(dash){
                                    //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                    //		//unit.PlayDash();
                                    //	}
                                    //}
                                }
                            }
                        }
                    }
                    else if (targetArea == _TargetingA.FrontalCone)
                    {
                        Collider[] cols = Physics.OverlapSphere(unit.thisT.position, range, maskTarget);
                        //if(cols!=null && cols.Length>0) Debug.Log(cols[0]);

                        if (cols.Length > 0)
                        {
                            Collider currentCollider = cols[0];
                            foreach (Collider col in cols)
                            {
                                Quaternion targetRot = Quaternion.LookRotation(col.transform.position - unit.thisT.position);
                                if (Quaternion.Angle(targetRot, unit.thisT.rotation) < frontalConeAngle)
                                {
                                    Unit targetTemp = currentCollider.gameObject.GetComponent <Unit>();
                                    if (targetTemp != null && targetTemp.HPAttribute.HP > 0)
                                    {
                                        target = targetTemp;
                                        if (attackMode == _AttackMode.StopNAttack)
                                        {
                                            if (attackMethod != _AttackMethod.Melee)
                                            {
                                                unit.StopAnimation();
                                            }
                                            unit.StopMoving();
                                            //if(dash){
                                            //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                            //		//unit.PlayDash();
                                            //	}
                                            //}
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if (targetArea == _TargetingA.Obstacle)
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(unit.thisT.position, unit.thisT.forward, out hit, range, maskTarget))
                        {
                            Unit targetTemp = hit.collider.gameObject.GetComponent <Unit>();
                            if (targetTemp != null && targetTemp.HPAttribute.HP > 0)
                            {
                                target = targetTemp;
                                if (attackMode == _AttackMode.StopNAttack)
                                {
                                    if (attackMethod != _AttackMethod.Melee)
                                    {
                                        unit.StopAnimation();
                                    }
                                    unit.StopMoving();
                                    //if(dash){
                                    //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                    //		//unit.PlayDash();
                                    //	}
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //if target is out of range or dead or inactive, clear target
                currentTargetDist = Vector3.Distance(unit.thisT.position, target.GetTargetT().position);
                                #if UNITY_4_0
                if (currentTargetDist > range * 1.25f || target.HPAttribute.HP <= 0 || !target.thisObj.activeInHierarchy)
                {
                                #else
                if (currentTargetDist > range * 1.25f || target.HPAttribute.HP <= 0 || !target.thisObj.active)
                {
                                #endif
                    target = null;
                    if (attackMode == _AttackMode.StopNAttack)
                    {
                        unit.ResumeAnimation();
                        unit.ResumeMoving();
                        //Debug.Log("target cleared");
                    }
                    if (meleeState == _MeleeState.Attacking)
                    {
                        meleeState = _MeleeState.OutOfRange;
                    }
                }
            }
            yield return(null);
        }
    }
Пример #3
0
    IEnumerator ScanForTarget()
    {
        LayerMask maskTarget=1<<LayerManager.LayerTower();
        while(true){
            if(target==null){
                if(unit.HasStoppedMoving()){
                    unit.ResumeAnimation();
                    unit.ResumeMoving();
                }

                if(targetArea==_TargetingA.AllAround){

                        Collider[] cols=Physics.OverlapSphere(unit.thisT.position, range, maskTarget);
                        //if(cols!=null && cols.Length>0) Debug.Log(cols[0]);

                        if(cols.Length>0){
                            Collider currentCollider=cols[Random.Range(0, cols.Length)];
                            Unit targetTemp=currentCollider.gameObject.GetComponent<Unit>();
                            if(targetTemp!=null && targetTemp.HPAttribute.HP>0){
                                target=targetTemp;

                                if(attackMode==_AttackMode.StopNAttack){
                                    if(attackMethod!=_AttackMethod.Melee) unit.StopAnimation();
                                    unit.StopMoving();
                                    //if(dash){
                                    //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                    //		//unit.PlayDash();
                                    //	}
                                    //}
                                }
                            }
                        }

                }
                else if(targetArea==_TargetingA.FrontalCone){

                        Collider[] cols=Physics.OverlapSphere(unit.thisT.position, range, maskTarget);
                        //if(cols!=null && cols.Length>0) Debug.Log(cols[0]);

                        if(cols.Length>0){
                            Collider currentCollider=cols[0];
                            foreach(Collider col in cols){
                                Quaternion targetRot=Quaternion.LookRotation(col.transform.position-unit.thisT.position);
                                if(Quaternion.Angle(targetRot, unit.thisT.rotation)<frontalConeAngle){
                                    Unit targetTemp=currentCollider.gameObject.GetComponent<Unit>();
                                    if(targetTemp!=null && targetTemp.HPAttribute.HP>0){
                                        target=targetTemp;
                                        if(attackMode==_AttackMode.StopNAttack){
                                            if(attackMethod!=_AttackMethod.Melee) unit.StopAnimation();
                                            unit.StopMoving();
                                            //if(dash){
                                            //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                            //		//unit.PlayDash();
                                            //	}
                                            //}
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                }
                else if(targetArea==_TargetingA.Obstacle){

                        RaycastHit hit;
                        if(Physics.Raycast(unit.thisT.position, unit.thisT.forward, out hit, range, maskTarget)){
                            Unit targetTemp=hit.collider.gameObject.GetComponent<Unit>();
                            if(targetTemp!=null && targetTemp.HPAttribute.HP>0){
                                target=targetTemp;
                                if(attackMode==_AttackMode.StopNAttack){
                                    if(attackMethod!=_AttackMethod.Melee) unit.StopAnimation();
                                    unit.StopMoving();
                                    //if(dash){
                                    //	if(Vector3.Distance(unit.thisT.position, target.thisT.position)>8){
                                    //		//unit.PlayDash();
                                    //	}
                                    //}
                                }
                            }
                        }

                }
            }
            else{

                //if target is out of range or dead or inactive, clear target
                currentTargetDist=Vector3.Distance(unit.thisT.position, target.thisT.position);
                if(currentTargetDist>range*1.25f || target.HPAttribute.HP<=0 || !target.thisObj.active){
                    target=null;
                    if(attackMode==_AttackMode.StopNAttack){
                        unit.ResumeAnimation();
                        unit.ResumeMoving();
                        //Debug.Log("target cleared");
                    }
                    if(meleeState==_MeleeState.Attacking){
                        meleeState=_MeleeState.OutOfRange;
                    }
                }
            }
            yield return null;
        }
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (type == _AttackCreepType.Attack)
        {
            if (target != null)
            {
                if (attackMethod == _AttackMethod.Melee)
                {
                    if (attackMode == _AttackMode.StopNAttack)
                    {
                        LayerMask mask = 1 << LayerManager.LayerTower();
                        if (!Physics.Raycast(unit.thisT.position + new Vector3(0, 1, 0), unit.thisT.forward, meleeAttackRange, mask))
                        {
                            MoveToPoint(target.GetTargetT().position);
                        }
                        else
                        {
                            if (meleeState != _MeleeState.Attacking)
                            {
                                unit.StopAnimation();
                                meleeState  = _MeleeState.Attacking;
                                targetInLOS = true;
                            }
                        }
                    }
                    else
                    {
                        LayerMask mask = 1 << LayerManager.LayerTower();

                        if (Physics.Raycast(unit.thisT.position + new Vector3(0, 1, 0), unit.thisT.forward, meleeAttackRange, mask))
                        {
                            if (meleeState != _MeleeState.Attacking)
                            {
                                //unit.StopAnimation();
                                meleeState  = _MeleeState.Attacking;
                                targetInLOS = true;
                            }
                        }
                        else
                        {
                            if (meleeState == _MeleeState.Attacking)
                            {
                                meleeState  = _MeleeState.OutOfRange;
                                targetInLOS = false;
                            }
                        }
                    }
                }
                else if (attackMethod == _AttackMethod.Range)
                {
                    if (turretObject != null)
                    {
                        TurretRoutine();

                        Quaternion wantedRot = Quaternion.LookRotation(target.GetTargetT().position - unit.thisT.position);

                        //~ turretObject.rotation=Quaternion.Slerp(turretObject.rotation, wantedRot, Time.deltaTime*10);

                        //~ if(Quaternion.Angle(wantedRot, turretObject.rotation)<10){
                        //~ targetInLOS=true;
                        //~ }
                        //~ else targetInLOS=false;

                        if (attackMode == _AttackMode.StopNAttack)
                        {
                            Vector3 point = target.GetTargetT().position;
                            point.y             = unit.thisT.position.y;
                            wantedRot           = Quaternion.LookRotation(point - unit.thisT.position);
                            unit.thisT.rotation = Quaternion.Slerp(unit.thisT.rotation, wantedRot, 10 * Time.deltaTime);
                        }
                    }
                    else
                    {
                        if (attackMode == _AttackMode.StopNAttack)
                        {
                            Vector3 point = target.GetTargetT().position;
                            point.y = unit.thisT.position.y;

                            Quaternion wantedRot = Quaternion.LookRotation(point - unit.thisT.position);
                            unit.thisT.rotation = Quaternion.Slerp(unit.thisT.rotation, wantedRot, 10 * Time.deltaTime);
                            //Debug.Log("range, stop and attack   "+Quaternion.Angle(unit.thisT.rotation, wantedRot));
                            if (Quaternion.Angle(unit.thisT.rotation, wantedRot) < 10)
                            {
                                if (!targetInLOS)
                                {
                                    targetInLOS = true;
                                }
                            }
                            else if (targetInLOS)
                            {
                                targetInLOS = false;
                            }
                        }
                        else
                        {
                            if (!targetInLOS)
                            {
                                targetInLOS = true;
                            }
                        }
                    }
                }
            }
            else
            {
                if (targetInLOS)
                {
                    targetInLOS = true;
                }

                if (attackMethod == _AttackMethod.Melee)
                {
                }
                else if (attackMethod == _AttackMethod.Range)
                {
                    if (turretObject != null)
                    {
                        //~ Quaternion wantedRot=Quaternion.Euler(0, 0, 0);

                        //~ turretObject.localRotation=Quaternion.Slerp(turretObject.localRotation, wantedRot, Time.deltaTime*10);

                        ResetTurretRoutine();
                    }
                }
            }
        }
        else if (type == _AttackCreepType.Support)
        {
            if (attackMode == _AttackMode.StopNAttack)
            {
            }
            else if (attackMode == _AttackMode.RunNGun)
            {
            }
        }
    }