Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tom1103 · Nov 03, 2012 at 03:45 PM · materialchangecolour

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; }

}

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZenithCode · Nov 03, 2012 at 04:25 PM 0
Share

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.

avatar image tom1103 · Nov 03, 2012 at 04:49 PM 0
Share

When the player exit the game

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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();
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tom1103 · Nov 03, 2012 at 05:16 PM 0
Share

I added this: gameObject.renderer.material.color = newcolorball; for the new color and I get errors what did I wrong?

avatar image ZenithCode · Nov 03, 2012 at 07:08 PM 0
Share

newcolorball is of type material so you have to type gameObject.renderer.material = newcolorball

avatar image tom1103 · Nov 04, 2012 at 07:53 AM 0
Share

Thanks it's was stupid my color script

avatar image ZenithCode · Nov 04, 2012 at 10:08 AM 0
Share

Please accept this as the correct answer! :-)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges