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
1
Question by sriram90 · Feb 15, 2011 at 09:32 AM · coloronmousedownhighlight

highlight object color

Hi folks,

i have 5 cylinder objects.. if i click on any one of cylinder the color should be changed and remain unchanged like wise for all those cylinders...

how could i script for that??

i have already tried but no luck....

public int id;

void Update() { if(!clicked) renderer.material.color = Color.yellow;

}

void OnMouseDown() { for(id=1; id<=5; i++) { if(GameObject.Find("cylinder"+i)) { clicked = true; renderer.material.color = Color.red; } }

}

thanks in advance....sorry about my english...

Comment
Add comment · Show 7
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 StephanK · Feb 15, 2011 at 10:07 AM 0
Share

So you want the color for all 5 cylinders changed to red when you click on any one of them? And it should change back to yellow when you release the button? Just trying to understand the question. ;)

avatar image sriram90 · Feb 15, 2011 at 10:38 AM 0
Share

nope spree...clicked cylinder only change the color to red..all others remains in yellow...if you click any one of them that particular cylinder color only to be change... hope you understand...

avatar image sriram90 · Feb 15, 2011 at 10:46 AM 0
Share

hi spree.... have you got my ques???

avatar image lampshade · Feb 15, 2011 at 12:11 PM 0
Share

So I am a green. I click a cyl and they ALL Change to green? If I am a red, they all change from green to red?

avatar image lampshade · Feb 15, 2011 at 12:13 PM 0
Share

Dont be confused with releasing the mouse button; just put code inside of On$$anonymous$$ouseDown() for when you want something to happen when a mouse is clicked.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sriram90 · Feb 17, 2011 at 06:30 AM

Problem Solved [highlight object color]

i have tried it with 2 scripts....same 5 cylinders and i noted with id's id=1,2,...5.

its in first "cylinder.cs" script:

public int id; public static bool cylinderSelected,click,isClicked; public static int selectedId; private Color initialColor;

void Start () { initialColor = renderer.material.color; }

void Update () { if(!isClicked) { renderer.material.color = initialColor; } }

void OnMouseDown() { if(id <= 5) {
click = true; selectedId = id; if(GameObject.FindWithTag("cylinder"+id)) { isClicked = true; renderer.material.color = Color.cyan; } } cylinderSelected = true;// i used this for another purpose..dont confuse.. }

now we can control it with "GamePlay.cs" script:

void Update()
{
if(cylinder.click)
{
cylinder.click = false;
cylinder script;
for(int i=1; i<= 5; i++)
{
if(i != cylinder.selectedId)
{
GameObject find = GameObject.FindWithTag("cylinder"+i);
if(find != null)
{
script = find.GetComponent<cylinder>(); // changed the values in cylinder scripts.
script.isClicked = false;
}
}
}
}

thats it....

now it'll come like this, if you click of an object that particular only highlighted..remaining objects wont be highlighted... you may try it...if you have any doubts about it, share it with me....

thanks...

Comment
Add comment · Show 1 · 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 Ben Blaut · Jul 23, 2012 at 04:21 PM 0
Share

This code doesn't even come close to compiling. It's hard to even tell what you're doing here.

avatar image
0

Answer by lampshade · Feb 15, 2011 at 12:19 PM

//You may need to use raycasting to incidate if you have clicked an object in world space.

public class ClyindricalColorz : MonoBehaviour { public GameObject[ ] Cylins = new GameObject(); //depending if you have the Cylins in the scene //drag them into the array, 1st making size > 0 private void UpdateColor(GameObject[ ] myCylins) { if (OnMouseDown()) { myCylins[0].renderer.material.color = Color.red; //myCylins[1].renderer.material.color = Color.red; }

 }

 private void Update() {
     UpdateColor(Clyins[0]);//First Cylindrical GameObject.
     //UpdatColor(Clyins[1]);

 }

}

Comment
Add comment · Show 2 · 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 sriram90 · Feb 15, 2011 at 12:50 PM 0
Share

hi lampshade.... ya i tried your script...i dont want all those objects changed the color...i just want if i click on a cylinder that particular only change as red....consider if i click on cylinder1 that only should be red..others are yellow.....if i click on cylinder2 all other changed as yellow and cylinder2 only as red...like this....have u got my ques now??? hope you understand well....

avatar image sriram90 · Feb 17, 2011 at 06:36 AM 0
Share

lampshade's answer only for if you click on a object all objects color should be change....

avatar image
0

Answer by Unamine · Feb 15, 2011 at 01:03 PM

Take a look at the videos: Burg Zerg Arcade, teaches him to do so (in C #) and also a full RPG.

To your question take a look at:

  1. Unity3D Tutorial - Targeting Enemies 1 / 3
  2. Unity3D Tutorial - Targeting Enemies 2 / 3
  3. Unity3D Tutorial - Targeting Enemies 3 / 3

Links from tutorials:

http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial

Comment
Add comment · Show 1 · 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 ocimum · Oct 19, 2015 at 09:32 AM 0
Share

Link is broken

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

2 People are following this question.

avatar image avatar image

Related Questions

changing material color through C# script 0 Answers

Need help with my script - Rollover change material and click change material 0 Answers

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Highlight other players - Networking 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