- Home /
BCE0019: 'height' is not a member of 'UnityEngine.Collider'.
Can anyone explicitly typecasting this for me to use it as referance. This is rigidcontroller.js. file. Error at 'height' and 'radius' when I try to build on Android
@script RequireComponent(Rigidbody, CapsuleCollider)
function Awake (){ rigidbody.freezeRotation = true; rigidbody.useGravity = false; myTransform = transform; mainCameraGO = gameObject.FindWithTag("MainCamera"); weaponCameraGO = gameObject.FindWithTag("WeaponCamera"); rayDistance = collider.height * .5 + collider.radius; playerWeapons.animation.wrapMode = WrapMode.Loop; }
Answer by Kryptos · Jul 24, 2012 at 02:05 PM
height is a member of CapsuleCollider. But the generic property collider is of type Collider. You have to cast it to CapsuleCollider prior to accessing its variables.
In C#, you would do:
void Awake()
{
// ...
CapsuleCollider capsule = (CapsuleCollider) collider;
// or even safier
CapsuleCollider capsule = GetComponent<CapsuleCollider>();
// then check it, and access it
if (capsule)
{
rayDistance = collider.height * 0.5f + collider.radius;
}
}
So in UnityScript it should look like:
function Awake()
{
// ...
var capsule : CapsuleCollider = collider as CapsuleCollider;
// or even safier
var capsule : CapsuleCollider = GetComponent.<CapsuleCollider>();
// then check it, and access it
if (capsule)
{
rayDistance = collider.height * .5 + collider.radius;
}
}
Note: only one of the alternative to get the component.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074621im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
error for array functions 2 Answers
finish line script 3 Answers
transform.position not a member??? 2 Answers
dynamic typing in Unity iOS: ...not a member of 'UnityEngine.Component' 2 Answers