cannot seem to set the radius and height of capsule collider added to object on instantiate.

It adds a capsule collider but will not set the height and radius to those values.

public CapsuleCollider sc;

    void Awake()
    {
        CapsuleCollider sc = gameObject.AddComponent<CapsuleCollider>();
        cloudthree = CloudScript.gameObject.GetComponent<CloudThree>();
    }

    void Start()
    {

        sc.height = 0.03f;
        sc.radius = 0.3f;
    }

Your code shouldn’t even compile because you’re defining sc twice.

CapsuleCollider sc = gameObject.AddComponent<CapsuleCollider>();

Should be:

sc = gameObject.AddComponent<CapsuleCollider>();
1 Like

It does compile…wierd tho, ill fix it. Either or way It is not setting the height and radius, so do you see any issues in my code in regards to the height or radius portions?

You create the capsule collider in the Awake, but you also give it a type. This means that it makes a local instance of it, then destroys that local instance at the end of the awake…

public CapsuleCollider sc;
 
    void Awake()
    {
        sc = gameObject.AddComponent<CapsuleCollider>();
        cloudthree = CloudScript.gameObject.GetComponent<CloudThree>();
    }
 
    void Start()
    {
 
        sc.height = 0.03f;
        sc.radius = 0.3f;
    }

It will have no problem compiling.

this is a scope issue

1 Like

I saw in the API library that the height has Vector3 values, example ( 3, 5 ,65 ) instead of my float values. Am I correct in the values I tried to assign for height and radius being float values?

Height is a float. http://docs.unity3d.com/ScriptReference/CapsuleCollider-height.html