- Home /
Illuminating a 3D object's edges OnMouseOver (script in c#)?
Hi everyone,
I am new in coding and unity in general. I am working on a simulation, scripted in c#.
I want that when the player mouses over a 3D object the edges of the 3D object Illuminate as a green or blue line (not that the color really matters in code). Is this possible to do? and if it is, how would I do that?
This is what I have now:
using UnityEngine;
using System.Collections;
public class myscript : MonoBehaviour {
private Color initialColor;
void Start()
{
initialColor = renderer.material.color;
}
void OnMouseOver ()
{
renderer.material.color = Color.green;
}
void OnMouseExit ()
{
renderer.material.color = initialColor;
}
}
It works but what happens with this code is that you just change the main color of the texture and that is not what I want.
Thank you in advance for your input!
Answer by Graham-Dunnett · Jun 07, 2014 at 09:45 AM
You're changing the colour of the object, not rendering an outline around it. Rendering outline is not easy. One way to do this is to move the object closer to the camera, and render it with a flat shader. Do this without writing to the z-buffer. Then render your object normally, at the correct position. You should then have the flat shaded edge showing. (Moving the copy closer to the camera makes it larger.)
Thnx for the info, now I atleast know that I have to search for the word "outline" and 1 way to make an outline.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
OnMouseOver still works on disabled script 1 Answer
How to get a pop-up window floating next to a gameobject? 1 Answer