CharacterController2D.recalculateDistanceBetweenRays C# (CSharp) Method

recalculateDistanceBetweenRays() public method

this should be called anytime you have to modify the BoxCollider2D at runtime. It will recalculate the distance between the rays used for collision detection. It is also used in the skinWidth setter in case it is changed at runtime.
public recalculateDistanceBetweenRays ( ) : void
return void
	public void recalculateDistanceBetweenRays()
	{
		// figure out the distance between our rays in both directions
		// horizontal
		var colliderUseableHeight = boxCollider.size.y * Mathf.Abs( transform.localScale.y ) - ( 2f * _skinWidth );
		_verticalDistanceBetweenRays = colliderUseableHeight / ( totalHorizontalRays - 1 );

		// vertical
		var colliderUseableWidth = boxCollider.size.x * Mathf.Abs( transform.localScale.x ) - ( 2f * _skinWidth );
		_horizontalDistanceBetweenRays = colliderUseableWidth / ( totalVerticalRays - 1 );
	}

Usage Example

コード例 #1
0
    void ChangeState()
    {
        audio.pitch = Random.Range(1.0f, 2.0f);

        if (currState == shiftState.HUMAN)
        {
            Camera.main.GetComponent <VignetteAndChromaticAberration> ().chromaticAberration = 100;
            currState  = shiftState.WOLF;
            currDamage = w_damage;
            StartCoroutine(pCtrl.ShapeShift());
            StartCoroutine(Shake());
            audio.PlayOneShot(shiftSound);
            transform.position = new Vector2(transform.position.x, transform.position.y);
            col.size           = new Vector2(0.5f, 0.7f);
            col.offset         = new Vector2(0, 0.4f);
            cc.recalculateDistanceBetweenRays();
        }
        else
        {
            currState  = shiftState.HUMAN;
            currDamage = h_damage;
            StartCoroutine(pCtrl.ShapeShift());
            Camera.main.GetComponent <VignetteAndChromaticAberration> ().chromaticAberration = 100;
            StartCoroutine(Shake());
            audio.PlayOneShot(shiftSound);
            transform.position = new Vector2(transform.position.x, transform.position.y);
            col.size           = new Vector2(0.5f, 1.2f);
            col.offset         = new Vector2(0, 0.6f);
            cc.recalculateDistanceBetweenRays();
        }

        audio.pitch = 1;
    }
All Usage Examples Of CharacterController2D::recalculateDistanceBetweenRays