Unit.FittedCharacterCollider C# (CSharp) Method

FittedCharacterCollider() private method

private FittedCharacterCollider ( ) : void
return void
    private void FittedCharacterCollider()
    {
        Transform transform = this.gameObject.transform;
        Quaternion rotation = transform.rotation;
        transform.rotation = Quaternion.identity;

        characterController = transform.GetComponent<CharacterController> ();

        if (characterController == null) {
            transform.gameObject.AddComponent<CharacterController> ();
            characterController = transform.GetComponent<CharacterController> ();
        }

        Bounds bounds = new Bounds (transform.position, Vector3.zero);

        ExtendBounds (transform, ref bounds);

        characterController.center = new Vector3((bounds.center.x - transform.position.x) / transform.localScale.x, (bounds.center.y - transform.position.y + 0.1f) / transform.localScale.y, (bounds.center.z - transform.position.z) / transform.localScale.z);
        characterController.radius = bounds.size.x / 2;
        characterController.height = bounds.size.y / transform.localScale.y;

        transform.rotation = rotation;
    }