- Home /
When complete level change colour of ball.
Hi I have a problem I want to make a game when you Entertrigger that the next time the ball has another colour?
EnterTrigger script:
function OnTriggerEnter(other : Collider) {
PlayerPrefs.SetInt("newcolor", 1);
Debug.Log("newcolor = ball-special");
yield WaitForSeconds(2.0); Application.LoadLevel("menu"); }
and the change colour for the ball script:
var newcolorball : Material; var newcolor : int = 0; var levelReached1 : int = 0;
function Start () {
}
function Update () {
newcolor = PlayerPrefs.GetInt("newcolor");
if(newcolor){
find.gameObjectwithTag("ball");{
renderer.material.newcolorball; }
}
}
Do you want to persist this when player exits game or you just want to change colour whenever player goes into your trigger? If the latter, do not use PlayerPrefs.
Answer by ZenithCode · Nov 03, 2012 at 05:08 PM
Try this:
function Start()
{
if (PlayerPrefs.GetInt("newcolor") == 1)
{
//Change colour here
}
}
function OnTriggerEnter(other : Collider) {
PlayerPrefs.SetInt("newcolor", 1);
PlayerPrefs.Save();
}
I added this: gameObject.renderer.material.color = newcolorball; for the new color and I get errors what did I wrong?
newcolorball is of type material so you have to type gameObject.renderer.material = newcolorball
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to change the colour of my car? 1 Answer
referring to a particular material 0 Answers
Audio Fades 1 Answer
Problem with line renderer material 3 Answers