Beispiel #1
0
 void Awake()
 {
     _detector    = transform.GetChild(0).GetComponent <PlayerDetection>();
     _postSearch  = GetComponentInChildren <FindPlayer>();
     _patrolBehav = GetComponent <Patrol>();
     _spriteHand  = GetComponent <Spritehandler>();
     _coneRender  = transform.GetChild(0).GetComponent <VisionConeRender>();
 }
    /**
     * Creates 4 points for vision cone shape, left and right are just reverse of each other
     * Get the appropriate compoenent and assign them starting values
     */
    private void SetUpVisionCone()
    {
        _leftVision.Add(new Vector2(-0.2f, 0.5f));
        _leftVision.Add(new Vector2(-5f, 1.6f));
        _leftVision.Add(new Vector2(-5f, -0.8f));
        _leftVision.Add(new Vector2(-0.2f, _detection.GetEyeDistance()));


        for (int i = 0; i < 4; i++)
        {
            var rightEye = Vector2.Scale(_leftVision.ElementAt(i), new Vector2(-1f, 1f));
            _rightVision.Add(rightEye);
        }

        _visionCone        = GetComponent <PolygonCollider2D>();
        _visionCone.points = _rightVision.ToArray();

        _coneRender = GetComponent <VisionConeRender>();
        _coneRender.SetConeShape(_visionCone.points);
        _coneRender.ActivateState(_blind);
    }