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 Julian-S · Jun 04, 2013 at 08:32 PM · networkingplayercolorhighlightother

Highlight other players - Networking

So my networking is going well so far except for one thing. I have two scripts that worked on other objects when the game wasn't built for networking, but they no longer function properly and behave oddly.

The effect of the first script is to highlight objects blue when your cursor goes over them.

The effect of the second script is that if you left mouse click on the target, it stays highlighted blue (except if it's yourself).

When I build and play a network game, they function fine for highlighting my own player, however, when I put my mouse over another player, it turns them black and they just stay that way even if the cursor goes off of them.

I can still click on the enemies and it targets them and I can shoot at them, the odd thing is that they turn black when the script should be highlighting their original color to a blue. Both scripts are attached to the player object.

I want the other players to be highlighted blue for just the player doing the on mouse over and the targeting.

HighlightScript (first script)

 private float blueMultiply = 3.50f;
 
     private float redGreenMultiply = 0.50f; 
 
  
 
     private Color originalColor;
 
  
 
     private void Start()
 
     {
         if(networkView.isMine == true )
         {
 
         originalColor = gameObject.renderer.material.color;
             
         }
         else
         {
             enabled = false;
         }
         
 
     }
 
  
 
     void OnMouseEnter()
 
     {
 
         AddHighlight();
 
     }
 
  
 
     void OnMouseExit()
 
     {
 
         RemoveHighlight();
 
     }
 
  
 
     private void  AddHighlight() 
 
     {
 
         float red = originalColor.r * redGreenMultiply;
 
         float blue = originalColor.b * blueMultiply;
 
         float green = originalColor.g * redGreenMultiply;
 
  
 
         gameObject.renderer.material.color = new Color(red, green, blue);
 
     }
 
  
 
     private void RemoveHighlight()
 
     {
 
         gameObject.renderer.material.color = originalColor;
 
     }
     



Targeting Script:

                 //targeting
                 if (Input.GetMouseButtonDown(0))
                 {
                     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                     if (Physics.Raycast (ray, out hit, Mathf.Infinity)){
                         if (hit.transform.tag == "Player"){
                             if (hasTarget)
                             {
                                 RemoveHighlightOnTarget();
                             }
                             if (hit.transform.gameObject != gameObject)
                             {
                                 go = hit.transform.gameObject;
                                 target = go.transform;
                                 hasTarget = true;
                                 originalColor = go.renderer.material.color;
                                 AddHighlightOnTarget();
                             }
                             //Debug.Log (go.renderer.material.color);
                         }
                     }
                 }  
                 if (go == null)
                 {
                     hasTarget = false;
                 }
 

Any insight on this would be greatly appreciated! Thanks

Comment
Add comment · Show 4
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 Julian-S · Jun 04, 2013 at 08:30 PM 0
Share

Also part of the targeting script:

     //These Variables
 private float blue$$anonymous$$ultiply = 3.50f;
     private float redGreen$$anonymous$$ultiply = 0.50f;
     private Color originalColor;
 
 
 //Highlight Function on target
     private void  AddHighlightOnTarget() 
 
     {
 
         float red = originalColor.r * redGreen$$anonymous$$ultiply;
 
         float blue = originalColor.b * blue$$anonymous$$ultiply;
 
         float green = originalColor.g * redGreen$$anonymous$$ultiply;
 
  
 
         go.renderer.material.color = new Color(red, green, blue);
         
 
     }
     
     
     
     //Remove highlight from target
      private void RemoveHighlightOnTarget()
 
     {
         go.renderer.material.color = originalColor;
 
     }
     


     
avatar image Jamora · Jun 04, 2013 at 08:37 PM 0
Share

What happens if you remove the else branch in the start method of the first script?

avatar image Julian-S · Jun 04, 2013 at 08:39 PM 0
Share

I'll give it a shot! I also have a similar else branch in the second script so I'll try removing that one as well, or combining that part of the script.

avatar image Julian-S · Jun 04, 2013 at 08:51 PM 0
Share

Nothing, other players still turn black. The owned player highlights properly still.

I combined the scripts into one, here's the updated one with the else taken out:

  using UnityEngine;
     using System.Collections;
     
     public class HighlightScript : $$anonymous$$onoBehaviour {
     
         private float blue$$anonymous$$ultiply = 3.50f;
     
         private float redGreen$$anonymous$$ultiply = 0.50f; 
     
      
     
         private Color originalColor;
         private Color originalColor2;
         public bool hasTarget = false;
         public Transform target;
         public GameObject go;
         
             //Raycast targetting
         public RaycastHit hit;
         public Ray ray;
     
      
     
         private void Start()
     
         {
             if(networkView.is$$anonymous$$ine == true )
             {
     
             originalColor = gameObject.renderer.material.color;
                 
             }
             /*else
             {
                 enabled = false;
             }*/
             
     
         }
         
         void Update()
         {
             //targeting
                 if (Input.Get$$anonymous$$ouseButtonDown(0))
                 {
                     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                     if (Physics.Raycast (ray, out hit, $$anonymous$$athf.Infinity)){
                         if (hit.transform.tag == "Player"){
                             if (hasTarget)
                             {
                                 RemoveHighlightOnTarget();
                             }
                             if (hit.transform.gameObject != gameObject)
                             {
                                 go = hit.transform.gameObject;
                                 target = go.transform;
                                 hasTarget = true;
                                 originalColor2 = go.renderer.material.color;
                                 AddHighlightOnTarget();
                             }
                             
                         }
                     }
                     //Debug.Log (go.renderer.material.color);
                 }  
                 if (go == null)
                 {
                     hasTarget = false;
                 }
         }
      
     
         void On$$anonymous$$ouseEnter()
     
         {
     
             AddHighlight();
     
         }
     
      
     
         void On$$anonymous$$ouseExit()
     
         {
     
             RemoveHighlight();
     
         }
     
      
     
         private void  AddHighlight() 
     
         {
     
             float red = originalColor.r * redGreen$$anonymous$$ultiply;
     
             float blue = originalColor.b * blue$$anonymous$$ultiply;
     
             float green = originalColor.g * redGreen$$anonymous$$ultiply;
     
      
     
             gameObject.renderer.material.color = new Color(red, green, blue);
     
         }
     
      
     
         private void RemoveHighlight()
     
         {
     
             gameObject.renderer.material.color = originalColor;
     
         }
         
         
             //Highlight Function on target
         private void  AddHighlightOnTarget() 
     
         {
     
             float red = originalColor2.r * redGreen$$anonymous$$ultiply;
     
             float blue = originalColor2.b * blue$$anonymous$$ultiply;
     
             float green = originalColor2.g * redGreen$$anonymous$$ultiply;
     
      
     
             go.renderer.material.color = new Color(red, green, blue);
             
     
         }
         
         
         
         //Remove highlight from target
          private void RemoveHighlightOnTarget()
     
         {
             go.renderer.material.color = originalColor2;
     
         }
         
         
         
     }
 

1 Reply

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

Answer by Jamora · Jun 04, 2013 at 09:03 PM

If the remote computer network instantiates their player, then the if on line 27 is never entered on your computer, and a possibly null Color is used.

Comment
Add comment · Show 7 · 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 Julian-S · Jun 04, 2013 at 09:05 PM 0
Share

So should I get rid of the if statement there?

avatar image Julian-S · Jun 04, 2013 at 09:08 PM 0
Share

Interesting. If I do that, then the colors work. But now there is some weird behavior going on as for click them for targeting and being able to click yourself.

avatar image Jamora · Jun 04, 2013 at 09:08 PM 0
Share

Yes, if that doesn't do the trick, then I'm baffled.

avatar image Julian-S · Jun 04, 2013 at 09:11 PM 0
Share

Now I just need to figure out why clicking myself highlights the other player and how to fix that and so forth...

avatar image Jamora · Jun 04, 2013 at 09:16 PM 0
Share

The next thing I would try is to use this Start method private void Start() { if(networkView.is$$anonymous$$ine == false ) { originalColor = gameObject.renderer.material.color; } else { enabled = false; } }

Show more comments

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

15 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

Related Questions

Deleting a player over the network 1 Answer

Assigning Player Numbers 0 Answers

Unity networking tutorial? 6 Answers

Changing two different objects renderer colour 1 Answer

How to check when a new client/local player is loaded? 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