Пример #1
0
    public void ClearSensors()
    {
        foreach (var sensor in sensors)
        {
            Destroy(sensor.gameObject);
        }
        sensors.Clear();

        robot.GetComponent <Sensor>().Clear();
        exitSensor.Clear();
    }
Пример #2
0
 public override void UpdateInstruction()
 {
     if (executeNext)
     {
         instructionExecutor.ExecuteNextInstruction();
     }
     else
     {
         if (Math.Abs(robot.GetComponent <IsoTransform>().Position.x - targetPos.x) < .01f &&
             Math.Abs(robot.GetComponent <IsoTransform>().Position.y - targetPos.y) < .01f)
         {
             executeNext = true;
         }
     }
 }
Пример #3
0
 public override void UpdateInstruction()
 {
     if (executeNext)
     {
         instructionExecutor.ExecuteNextInstruction();
     }
     else
     {
         // Check robot is has reached it's destination
         if (robot.GetComponent <IsoTransform>().Position == targetPos)
         {
             executeNext = true;
         }
     }
 }
Пример #4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            _shiftClicked = true;
        }
        else if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            _shiftClicked = false;
        }

        if (_shiftClicked)
        {
            RobotFollowOrder();
        }

        Turning();

        if (Input.GetKeyDown("space"))
        {
            foundHealTarget = false;
        }
        if (Input.GetKey("space") && _stateManager.boltCount > 0)
        {
            // find robot to heal first
            if (!foundHealTarget)
            {
                RobotController closestRobot = robots[0];
                float           closestDist  = 20000;
                foreach (var robot in robots)
                {
                    if (!robot.isBroken && robot.GetComponent <Health>().currHealth < robot.GetComponent <Health>().maxHealth)
                    {
                        float dist = Vector3.Distance(robot.transform.position, transform.position);
                        if (closestDist > dist)
                        {
                            closestDist  = dist;
                            closestRobot = robot;
                        }
                    }
                }
                if (closestDist <= healRange)
                {
                    foundHealTarget = true;
                    healTarget      = closestRobot.GetComponent <Health>();
                    // tell robot to stop
                    closestRobot.isHealing = true;
                }
            }

            if (foundHealTarget && healTarget.currHealth < healTarget.maxHealth)
            {
                // Start heal
                healing = true;
                Vector3 robotPos = healTarget.transform.position;
                Vector3 healPos  = robotPos + (transform.position - robotPos).normalized * 0.7f;
                if (Vector3.Distance(healPos, transform.position) > 0.05f)
                {
                    transform.position =
                        Vector3.SmoothDamp(transform.position, healPos, ref _healMoveVelocity, Time.deltaTime * 10);
                }

                transform.LookAt(new Vector3(robotPos.x, transform.position.y, robotPos.z));

                anim.SetBool("isRepair", true);

                if (_currHealTime <= 0)
                {
                    // heal
                    healTarget.Heal(healAmount);
                    _stateManager.boltCount--;
                    _currHealTime = healTime;
                }

                _currHealTime -= Time.deltaTime;
            }
            else if (foundHealTarget && healTarget.currHealth == healTarget.maxHealth)
            {
                StopHealing();
                anim.SetBool("isRepair", false);
            }
        }
        else
        {
            StopHealing();
            anim.SetBool("isRepair", false);
        }

        healthBarPrefab.fillAmount = GetComponent <Health>().SendHp();
    }