- Home /
RE: rend.material too hard to handle for iOS?
I have 6 scripts like this, each assigned to a car (1,2,3,4,5,6). When I disable the scripts, the game doesn't crash, but if I keep them the game crashes. What could be the problem?
At awake I SetActive(true) the selected car and then this script is ran for the car that is active.
void Awake ()
{
if (PlayerPrefs.GetInt ("Selected Car") == 1) {
if (PlayerPrefs.GetInt ("Selected Colour 11") == 1) {
rend.material = Car01materials [0];
}
if (PlayerPrefs.GetInt ("Selected Colour 11") == 2) {
rend.material = Car01materials [1];
}
if (PlayerPrefs.GetInt ("Selected Colour 11") == 3) {
rend.material = Car01materials [2];
}
if (PlayerPrefs.GetInt ("Selected Colour 11") == 4) {
rend.material = Car01materials [3];
}
if (PlayerPrefs.GetInt ("Selected Colour 11") == 5) {
rend.material = Car01materials [4];
}
if (PlayerPrefs.GetInt ("Selected Colour 11") == 6) {
rend.material = Car01materials [5];
}
}
}
Check that Car01materials has a length of 6 or more and that it doesn't contain any null reference.
Check that rend is set to the right value.
Check that the all th keys you are using with GetInt are actually set.
Found the problem! I initiated a "Selected Colour 1(2,3,4,5,6)" on the title screen ins$$anonymous$$d of "Selected Colour 11(12,13,14,15,16).
You say "At awake I SetActive(true) the selected car and then this script is ran for the car that is active."
Try putting SetActive(true) in Start() so the above script runs first in Awake() then SetActive(true) in Start() ... Worth trying.
Answer by ippdev · May 18, 2015 at 07:35 AM
Get rid of the space before the opening square brackets.
$$anonymous$$akes sense! I'll try that when I get home and accept your answer then.
Thanks a lot!
It worked with one car, but when I added the script to the rest of the cars the game started crashing again. :(
$$anonymous$$akes sense!
No it doesn't actually, you can put as many whitespaces as you want before/after square brackets.
Have you got any clue what might be causing the crash? Is something too hard to handle for iOS?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Game crashes if it is not a development build 0 Answers
Distribute terrain in zones 3 Answers
How to change the color from code 1 Answer