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 8r3nd4n · Feb 05, 2014 at 10:10 PM · colorarrayslogictrailchange material

Change multiple gameobjects colour to create a trail

Hi

I have a grid type game where the player moves a cube 1 unit at a time in a grid like fashion (think like a chess board). On the player cube, there is a collider and on the board pieces there is a collider too. What I am trying to achieve is that each time the player moves to a new board piece, that particular piece gets brighter (modify the colour settings on that gameobjects material). This part is easy enough but what I would like is that the next piece that the player moves to gets its colour modified the brightest, and the previous one (that was the brightest), moves down in intensity. This continues for 4 pieces on the board so it shows the previous 4 moves of the player and they appear to fade colour in order of what was hit last.

I have an empty gameobject caller Trail which holds the script. This is where I think all this should be managed:

 using UnityEngine;
 using System.Collections;
 
 public class Trail : MonoBehaviour {
 
     public GameObject block1;
     public GameObject block2;
     public GameObject block3;
     public GameObject block4;
     // Use this for initialization
     void Start () {
         block1 = GameObject.Find("StartBlock").transform.FindChild("CubeWalls").gameObject;//the child object with the renderer on it
     }
 
     public void Shuffle()    //move the blocks down one position
     {
         block2 = block1;
         block3 = block2;
         block4 = block3;
         ChangeColour();
     }
 
     void ChangeColour()    //lighten the colour on each block by x amount
     {
         Color color = block1.renderer.materials[0].color;
         color.r += 0.2f;
         color.g += 0.2f;
         color.b += 0.2f;
         block1.renderer.material.color = color;
 
         Color color2 = block2.renderer.materials[0].color;
         color2.r += 0.4f;
         color2.g += 0.4f;
         color2.b += 0.4f;
         block2.renderer.material.color = color2;
 
         Color color3 = block3.renderer.materials[0].color;
         color3.r += 0.6f;
         color3.g += 0.6f;
         color3.b += 0.6f;
         block3.renderer.material.color = color3;
 
         Color color4 = block4.renderer.materials[0].color;
         color4.r += 0.8f;
         color4.g += 0.8f;
         color4.b += 0.8f;
         block4.renderer.material.color = color4;
     }
 }

Then on the pieces with the colliders, they should assign the current piece to the Trail script and then call shuffle on that script which should move the blocks down a position and subsequently change their colours but its within this logic that the thing doesn't work.

 using UnityEngine;
 using System.Collections;
 
 public class CheckColourChange : MonoBehaviour {
     
     public GameObject trail;
     public Trail traily;
 
     void Start()
     {
         trail = GameObject.Find("Trail");        //get the Trail gameobject that holds the script
         traily = trail.GetComponent<Trail>();    //get the Trail script from the Trail gameobject
     }
     void  OnTriggerEnter ( Collider other  )
     {
         
         traily.Shuffle();    //move all the blocks in the Trail script down a position
         traily.block1 = this.gameObject;    //assign this block to be block 1 in the Trail script
     }
 }



It seems to assign the previous piece to block2, block3 and block4 in the Trail script rather than moving them all one by one. So I guess there is a problem in the Shuffle function. I am also aware that I have my color values around the wrong way but thats an easy fix.

Also, it may be better to have the gameobjects in an array?

Any help appreciated.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trail Renderer's colors don't apply to material 1 Answer

Procedural construction 1 Answer

Logic error help: arrays and nested for loops 1 Answer

Trail of color behind the player 2D c# 1 Answer

Copy pixel color values to array 1 Answer


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