- Home /
extending car class from car tutorial
I'm trying to extend the Car class found in the car tutorial. I get the error line 23: expecting }, found 'wheels'. line 618: expecting EOF, found '}'
When I take away the surrounding "class Car extends Controllable{ }", it works fine. When I try extending MonoBehaviour/Behaviour/rigidbody I get the same error.
==== Controllable.js =====
#pragma strict
public var isPlayer:boolean=false;
protected var mouse_sensitivity:float=1000;
=============================
class Car extends Controllable{
private var wheelRadius : float = 0.4;
var suspensionRange : float = 0.1;
var suspensionDamper : float = 50;
var suspensionSpringFront : float = 18500;
var suspensionSpringRear : float = 9000;
public var brakeLights : Material;
var dragMultiplier : Vector3 = new Vector3(2, 5, 1);
var throttle : float = 0;
private var steer : float = 0;
private var handbrake : boolean = false;
var centerOfMass : Transform;
var frontWheels : Transform[];
var rearWheels : Transform[];
private var wheels : Wheel[];
wheels = new Wheel[frontWheels.Length + rearWheels.Length];
Answer by ScroodgeM · Aug 02, 2012 at 07:39 PM
in your example it's missed symbol '}' at the script's end
Sorry I forgot to mention that I didn't post the whole class because it was too long.
I found the problem, I had to put this line in Start() wheels = new Wheel[frontWheels.Length + rearWheels.Length];
It works fine when its not in a class. class Car extends Controllable{ ... }
Not sure why this happens though.
not in class you can use only variable declaration without dependencies. so instantiating an array based on other variables is impossible outside the method.
Your answer
Follow this Question
Related Questions
Got stuck trying to extend UnityPlayerActivity following example in Unity documentation. 1 Answer
Extend a line between two Vectors by a distance 0 Answers
How can i rotate my car steering wheel in accordance to the wheels? 1 Answer
Storing Data and Access Efficiency 0 Answers
Creating a SIMPLE car. 1 Answer