what is the meaning of this error BCE0019: 'position' is not a member of 'Object'. when i switch to android this error occurs but for pc platform code works fine no error, please tell me the reason behind this error.
/*i change the var path : Array; to var path : Transform[]; but path is not being created. and i remove
paragmastrict from script and put it again but not work.*/
var path : Array;
var pathGroup : Transform;
var maxSteer : float = 15.0 ;
var wheelFL : WheelCollider;
var wheelFR : WheelCollider;
var wheelRL : WheelCollider;
var wheelRR : WheelCollider;
var currentPathObj : int;
//var dir : float;
var centerOfMass : Vector3;
var distanceFromPath : float = 20;
var maxTorque : float = 50;
var currentSpeed : float ;
var topSpeed : float = 150;
var decellerationSpeed = 10;
var brakeingMesh : Renderer;
var idleBrakeLight : Material;
var activeBrakeLight : Material;
var isBrakeing : boolean;
var inSector : boolean ;
var sensorLength : float = 5;
var frontSensorStartPoint : float = 5;
var frontSensorSideDist : float ;
var frontSensorsAngle : float = 30;
var sidewaySensorLength : float =5 ;
var avoidSpeed : float = 10;
private var flag : int = 0;
var reversing : boolean = false;
var reverCounter : float = 0.0;
var waitToReverse : float = 3.0;
var reverFor : float = 1.5;
var respawnWait : float = 5;
var respawnCounter : float = 0.0;
function Start(){
rigidbody.centerOfMass = centerOfMass;
GetPath();
}
function GetPath(){
var path_objs : Array = pathGroup.GetComponentsInChildren(Transform);
path = new Array();
for(var path_obj : Transform in path_objs){
if(path_obj != pathGroup)
path[path.length] = path_obj;
}
}
function Update(){
if(flag == 0)
GetSteer();
Move();
BrakeingEffect();
Sensors();
Respawn();
}
function GetSteer() {
var steerVector : Vector3 = transform.InverseTransformPoint(Vector3(path[currentPathObj].position.x ,
transform.position.y , path[currentPathObj].position.z)) ;
var newSteer : float = maxSteer *(steerVector.x / steerVector.magnitude);
//dir = steerVector.x / steerVector.magnitude;
wheelFL.steerAngle = newSteer;
wheelFR.steerAngle = newSteer;
if(steerVector.magnitude <= distanceFromPath){
currentPathObj++;
}
if(currentPathObj >= path.length){
currentPathObj = 0;
}
}
function Move(){
currentSpeed = 2 (22/7) wheelRL.radius wheelRL.rpm 60/1000;
currentSpeed = Mathf.Round(currentSpeed);
if(currentSpeed <= topSpeed && !inSector){
if(!reversing){
wheelRL.motorTorque = maxTorque;
wheelRR.motorTorque = maxTorque;
}
else {
wheelRL.motorTorque = -maxTorque;
wheelRR.motorTorque = -maxTorque;
}
wheelRL.brakeTorque = 0;
wheelRR.brakeTorque = 0;
}
else if(!inSector){
wheelRL.motorTorque = 0;
wheelRR.motorTorque = 0;
wheelRL.brakeTorque = decellerationSpeed ;
wheelRR.brakeTorque = decellerationSpeed;
}
}
function BrakeingEffect(){
if(isBrakeing == true){
brakeingMesh.material = activeBrakeLight ;
}
else
brakeingMesh.material = idleBrakeLight;
}
function Sensors(){
flag = 0 ;
var avoidSenstivity : float =0 ;
var pos : Vector3 ;
var hit : RaycastHit ;
var rightAngle = Quaternion.AngleAxis(frontSensorsAngle , transform.up) * transform.forward;
var leftAngle = Quaternion.AngleAxis(-frontSensorsAngle , transform.up) * transform.forward;
pos = transform.position;
pos += transform.forward*frontSensorStartPoint;
// brakeing sensor.
if(Physics.Raycast(pos,transform.forward,hit,sensorLength)){
if(hit.transform.tag != "Terrain"){
flag++;
wheelRL.brakeTorque = decellerationSpeed;
wheelRR.brakeTorque = decellerationSpeed;
Debug.DrawLine(pos,hit.point,Color.red);
}
} else{
wheelRL.brakeTorque = 0;
wheelRR.brakeTorque = 0;
}
//front straight right sensor.
pos += transform.right*frontSensorSideDist;
if(Physics.Raycast(pos ,transform.forward , hit , sensorLength)){
if(hit.transform.tag != "Terrain"){
flag++;
avoidSenstivity -= 1;
Debug.Log("Avoiding");
Debug.DrawLine(pos,hit.point,Color.white);
}
}
else if(Physics.Raycast(pos , rightAngle , hit , sensorLength)){ //front angled right sensor.
if(hit.transform.tag != "Terrain"){
avoidSenstivity -= 0.5;
flag++;
Debug.DrawLine(pos,hit.point,Color.white);
}
}
// front straight left sensor.
pos = transform.position;
pos += transform.forward*frontSensorStartPoint;
pos -= transform.right*frontSensorSideDist;
if(Physics.Raycast(pos,transform.forward,hit,sensorLength)){
if(hit.transform.tag != "Terrain"){
flag++;
avoidSenstivity += 1;
Debug.Log("Avoiding");
Debug.DrawLine(pos,hit.point,Color.white);
}
}
else if(Physics.Raycast(pos,leftAngle,hit,sensorLength)){ //front angles left sensor.
if(hit.transform.tag != "Terrain"){
flag++;
avoidSenstivity += 0.5;
Debug.DrawLine(pos,hit.point,Color.white);
}
}
// rightsideWay sensor.
if(Physics.Raycast(transform.position,transform.right,hit,sidewaySensorLength)){
if(hit.transform.tag != "Terrain"){
flag++;
avoidSenstivity -= 0.5;
Debug.DrawLine(transform.position,hit.point,Color.white);
}
}
// leftsideWay sensor.
if(Physics.Raycast(transform.position,-transform.right,hit,sidewaySensorLength)){
if(hit.transform.tag != "Terrain"){
flag++;
avoidSenstivity += 0.5;
Debug.DrawLine(transform.position,hit.point,Color.white);
}
}
pos = transform.position;
pos += transform.forward*frontSensorStartPoint;
//front mid sensor.
if(avoidSenstivity == 0){
if(Physics.Raycast(pos,transform.forward,hit,sensorLength)){
if(hit.transform.tag != "Terrain"){
if(hit.normal.x < 0)
avoidSenstivity = -1;
else
avoidSenstivity = 1;
Debug.DrawLine(pos,hit.point,Color.white);
}
}
}
if(rigidbody.velocity.magnitude < 2 && !reversing){
reverCounter += Time.deltaTime;
if(reverCounter >= waitToReverse){
reverCounter = 0;
reversing = true;
}
}
else if(!reversing){
reverCounter = 0;
}
if(reversing){
avoidSenstivity *= -1;
reverCounter += Time.deltaTime;
if(reverCounter >= reverFor){
reverCounter = 0;
reversing = false; }
}
if(flag!= 0)
AvoidSteer(avoidSenstivity);
}
function AvoidSteer(senstivity : float){
wheelFL.steerAngle = avoidSpeed * senstivity;
wheelFR.steerAngle = avoidSpeed * senstivity;
}
function Respawn(){
if(rigidbody.velocity.magnitude < 2){
respawnCounter += Time.deltaTime;
if(respawnCounter >= respawnWait){
if(currentPathObj == 0){
transform.position = path[path.length -1].position;
}
else{
transform.position = path[currentPathObj -1 ].position;
}
respawnCounter = 0;
transform.localEulerAngles.z = 0;
}
}
}
when posting code, please format it so that it's readable to people trying to help you.
sorry for that but i won't know how to formate it .sorry again.
Unity Answers - How do you format scripts in Unity Answers?
Press the "101010" button
Answer by Jessespike · Dec 10, 2015 at 06:35 PM
JS Array class won't work with #pragma strict code, unless you manually cast to the correct type when retrieving items.
unity Wiki - Choosing the right collection type
Try changing
var path : Array;
to
import System.Collections.Generic;
var path : List.<Transform> = new List.<Transform>();
and revise your GetPath() function. I'm not sure what you're trying to do, but it doesn't look right. Try something like:
function GetPath(){
var path_objs : Array = pathGroup.GetComponentsInChildren(Transform);
for(var path_obj : Transform in path_objs){
if(path_obj != pathGroup)
path.Add(path_obj);
}
}
you'll also need change all of path's ".length" to ".Count"
Hi Jessespike , thanks for your relpy , its works . thanks alot Jessespike.
Your answer
Follow this Question
Related Questions
How to make questions & answers random in my script C#? 1 Answer
Move enemy only touching border 1 Answer
Arguement Out Of Range (ONLY IN BUILD) 1 Answer
A question about Unity Web Player 0 Answers