Im building a basic tower script an i want to have the size of my collider as a variable… Can anybody help me out please…
Here’s my javascript:
#pragma strict
class Energytower extends UpgradeTower {
public var name : String;
public var level : float;
public var damage : float;
public var range : float;
public var model : String;
public var type : String;
public var radius : float;
function Start () {
//this doesnt work
SphereCollider.radius = 10;
}
function Update () {
}
}
SphereCollider is the name of a class, rather than an instance of a class. The difference between the two is having the description of what a house is and trying to paint it (not possible!), versus actually having a house and trying to paint it (totally possible!).
To get an instance of that class (as long as it’s attached to the same GameObject your script is attached to), you use this line of code:
var mySphereCollider : SphereCollider = gameObject.GetComponent(SphereCollider);
And now you have an instance of a SphereCollider, you can change its attributes as such: