Beispiel #1
0
    private void LateUpdate()
    {
        bool tankIsSelected = mSelectedTank != null;

        SelectionHighlighterTrans.gameObject.SetActive(tankIsSelected);
        LineOfSightIndicator.gameObject.SetActive(tankIsSelected);
        DestinationIndicatorTrans.gameObject.SetActive(tankIsSelected);
        TargetIndicatorImage.gameObject.SetActive(tankIsSelected);

        if (!tankIsSelected)
        {
            return;
        }

        var newPos = mSelectedTank.transform.position;

        // Highlight tanks.
        newPos.y = SelectionHighlighterTrans.position.y;
        SelectionHighlighterTrans.position = newPos;

        // Indicate line of sight.
        newPos.y = LineOfSightIndicator.transform.position.y;
        LineOfSightIndicator.transform.position = newPos;
        LineOfSightIndicator.Range = mSelectedTank.pRange;
        LineOfSightIndicator.DrawFieldOfView();

        // Indicate destination.
        newPos   = mSelectedTank.pDestination;
        newPos.y = DestinationIndicatorTrans.position.y;
        DestinationIndicatorTrans.position = newPos;
        if (Vector3.Distance(mSelectedTank.transform.position, newPos) < 2f)
        {
            DestinationIndicatorTrans.gameObject.SetActive(false);
        }

        // Indicate target.
        Vector3 targetPos = Vector3.zero;

        if (mSelectedTank.Target.HasTarget(out targetPos))
        {
            TargetIndicatorImage.transform.SetAsFirstSibling();
            var screenPos = Camera.main.WorldToScreenPoint(targetPos);
            TargetIndicatorImage.transform.position = screenPos;
        }
        else
        {
            TargetIndicatorImage.gameObject.SetActive(false);
        }
    }