Beispiel #1
0
    private LightPolygon _LightPolygon;                 //	Reference to the light polygon

    /*--------------------------------------------------------------------------------------*/
    /*																						*/
    /*	Start: Runs once at the begining of the game. Initalizes variables.					*/
    /*																						*/
    /*--------------------------------------------------------------------------------------*/
    void Start()
    {
        SpriteRenderer spriteRenderer = GetComponent <SpriteRenderer> ();

        _Width  = spriteRenderer.bounds.extents.x;
        _Height = spriteRenderer.bounds.extents.y;

        _Seeker      = GetComponent <Seeker> ();
        _Rigidbody2D = GetComponent <Rigidbody2D> ();

        isOff        = false;
        followPlayer = false;

        if (gameObject.tag == "Enemy_YLLW")
        {
            _Rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
        }
        if (gameObject.tag == "Enemy_CYAN")
        {
            _Rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
        }
        if (gameObject.tag == "Enemy_MGNT")
        {
            _Rigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotation;
        }
        if (gameObject.tag == "Enemy_BLCK")
        {
            _Rigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotation;
            _LightPolygon            = GameObject.FindGameObjectWithTag("LightSource").GetComponent <LightPolygon> ();
            followPlayer             = true;
            inLight = true;
            StartCoroutine(CheckIfInLightPolygon());
        }

        if (target == null)
        {
            if (!_SerahcingForPlayer)
            {
                _SerahcingForPlayer = true;
                StartCoroutine(SearchForPlayer());
            }
            return;
        }

        //	Starts a new path to the target position, returns result to OnPathComplete method
        _Seeker.StartPath(transform.position, target.position, OnPathComplete);

        StartCoroutine(UpdatePath());
    }
    /*--------------------------------------------------------------------------------------*/
    /*																						*/
    /*	OnSceneGUI: Draws GUI on the scene view												*/
    /*																						*/
    /*--------------------------------------------------------------------------------------*/
    void OnSceneGUI()
    {
        //	Reference to LightPolyogn script
        LightPolygon lightpolygon = (LightPolygon)target;

        Handles.color = Color.white;
        //	Draws viewRadius
        Handles.DrawWireArc(lightpolygon.transform.position, Vector3.forward, Vector3.up, 360, lightpolygon.viewRadius);

        //	Draws viewAngle
        Vector3 viewAngleA = lightpolygon.DirectionFromAngle(-lightpolygon.viewAngle / 2, false);
        Vector3 viewAngleB = lightpolygon.DirectionFromAngle(lightpolygon.viewAngle / 2, false);

        Handles.DrawLine(lightpolygon.transform.position, lightpolygon.transform.position + viewAngleA * lightpolygon.viewRadius);
        Handles.DrawLine(lightpolygon.transform.position, lightpolygon.transform.position + viewAngleB * lightpolygon.viewRadius);

        Handles.color = Color.red;

        //	Draws line if visibleTargets are in the light
        foreach (Transform visibleTargets in lightpolygon.visibleTargets)
        {
            Handles.DrawLine(lightpolygon.transform.position, visibleTargets.position);
        }
    }