- Home /
Question by
Soul_Raven · Apr 19, 2015 at 10:21 PM ·
androidunity5mobile devicesenter-car
Script Crashing Game On Android Device (Unity 5)
This is a Car Door Script for i wrote in unity 4.6 version. I upgraded the project to Unity 5 and script works in the editor with unity remote. But when i build it to my phone it crashes the game.
Is there anything in this javaScript that causes my game to crash?
And yes you can use it in your own projects.
#pragma strict
var playerInVehicle = false;
var playerInRange = false;
var Char : GameObject;
var Car : GameObject;
var engine : GameObject;
var Cam1 : GameObject;
var Cam2 : GameObject;
var CarCamTarget : Transform;
var doorTexture : GUITexture;
var exitDoorTexture : GUITexture;
var carControls : GameObject;
var charactersControls : GameObject;
function Awake(){
engine.GetComponent(Engine).engineOn = false;
}
function Start (){
Cam2.SetActive(false);
Car.GetComponent(Vehicle).enabled = false;
}
function Update (){
Misc();
}
function Misc (){
if (playerInVehicle == true){
ParkingBrakeOff();
}
else if (playerInVehicle == false){
ParkingBrakeOn();
}
if (carControls){
Controls();
}
}
function OnTriggerStay(other : Collider){
if (other.tag == "Player"){
playerInRange = true;
}
}
function OnTriggerExit(other : Collider){
if (other.tag == "Player"){
playerInRange = false;
}
}
function Controls(){
for (var touch : Touch in Input.touches){
if (playerInRange == true){
if(touch.phase == TouchPhase.Began && doorTexture.HitTest (touch.position)){
if (playerInVehicle == false){
playerInVehicle = true;
Char.GetComponent.<Rigidbody>().isKinematic = true;
Char.SetActive(false);
yield WaitForSeconds(2);
Char.transform.parent = gameObject.transform;
Char.GetComponent.<Collider>().enabled = false;
engine.GetComponent(Engine).engineOn = true;
Car.GetComponent(Vehicle).enabled = true;
Cam1.SetActive(false);
Cam2.SetActive(true);
Cam2.GetComponent(SmoothFollow).target = CarCamTarget;
charactersControls.SetActive(false);
yield WaitForSeconds(2);
carControls.SetActive(true);
}
}
else if(touch.phase == TouchPhase.Began && exitDoorTexture.HitTest (touch.position)) {
if (playerInVehicle == true && Car.GetComponent(Vehicle).currentSpeed <= 0.5 && Car.GetComponent(Vehicle).currentSpeed >= -0.5){
playerInVehicle = false;
Car.GetComponent(Vehicle).enabled = false;
engine.GetComponent(Engine).engineOn = false;
carControls.SetActive(false);
yield WaitForSeconds(0.5);
charactersControls.SetActive(true);
Char.GetComponent.<Rigidbody>().isKinematic = false;
Char.GetComponent.<Collider>().enabled = true;
Char.SetActive(true);
Char.transform.parent = GameObject.Find("mobileControls").transform;
Char.transform.position.y += 0.4;
Char.transform.rotation.x = 0.00;
Char.transform.rotation.y = Car.transform.rotation.y;
Char.transform.rotation.z = 0.00;
Char.transform.localScale.x = 0.8704561;
Char.transform.localScale.y = 0.8704561;
Char.transform.localScale.z = 0.8704561;
Cam1.SetActive(true);
Cam2.SetActive(false);
}
}
}
}
}
function ParkingBrakeOn(){
Car.GetComponent(Vehicle).wheelfl.brakeTorque = 500;
Car.GetComponent(Vehicle).wheelfr.brakeTorque = 500;
Car.GetComponent(Vehicle).wheelrl.brakeTorque = 500;
Car.GetComponent(Vehicle).wheelrr.brakeTorque = 500;
}
function ParkingBrakeOff(){
Car.GetComponent(Vehicle).wheelfl.brakeTorque = 0;
Car.GetComponent(Vehicle).wheelfr.brakeTorque = 0;
Car.GetComponent(Vehicle).wheelrl.brakeTorque = 0;
Car.GetComponent(Vehicle).wheelrr.brakeTorque = 0;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613193414im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity5.4.0p4 compile error for android by il2cpp 1 Answer
Image appears clear on Iphone and strange on Android devices 0 Answers
Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE] (solved) 1 Answer
Is Build and Run essential to make a Gear VR app ? 1 Answer
Help with the new Mobile Notification System in Unity 1 Answer