So I am beginning to dive deeper into my first application.
I have a series of GameObjects that get created/instanced with new information attached to them. I would like to add some interactivity to them. Here’s what I’m wanting to do:
1: When I hover my mouse over one of the objects, I’d like it to be bracketed . I’d like it to always be facing the camera regardless of where the camera (billboard?) gets positioned/rotated in the scene. So my question is how would I do this? Would I do this with UI elements, or some other element?
2: When I click it, the bracket changes from to a circle that behaves the same way (custom texture/material)
Any help to point me in the right direction would be appreciated.
Sound boarding…*
I don’t think this will work. I’m trying to do something with custom textures. The LookAt option could force a 2D texture to Billboard to the camera perfectly.
The scaling I guess could be connected to the physical distance from the object .No real work needs to be done there which is a plus.
Ok. So I have finally started on the part of the project and I’m already running into a problem.
I was thinking that I could use a plane, but it doesn’t render (no texture)
I thought about using a Sprite.
Also, I am attempting to assign images in the variable but I’m getting errors. I’m assuming Image is not a valid type. Should I be using Texture instead?
What are your thoughts on using a plane vs using a Sprite?
I discovered the quad object… this makes alot more sense to use instead of the plane…
I still am not sure how to get the main texture to change based on onHover, offHover, and click/active states.
Check your images in the project library and you can set them to sprites instead of textures. Sprites can be placed in the Unity scene as is, without needing to apply them to any objects/geometry. They are specifically designed for putting flat/billboard images in Unity, are very well handled in code, and have more features than regular textures do!
Edit: You can also make a sprite, child it to the normal sprite, and make it appear or dissapar when the mouse is hovered over. Nice and simple.
If you put public Sprite thingie; in a script, then you can drag other sprites into it via the inspector and do the things such as making them visible, etc.
Edit 2: You can also use the free iTween to make cool bounce tweens or whatever when the sprite is clicked,
Last question of the night. I am attempting to use the for each loop to unhide/enable child transforms. I’ve tried a couple of different things but they do not behave as I wanted them to. (Specifically SetActive() )
so I did some research and some testing and I came across hit.transform. I modified the example given in the documentation to do my tests, but the outcome is not what I expected. If I click on the object that has this script, it returns the transform. Perfect. Expected that.
However, if I click outside the object nothing happens. Why is that? The logic here makes me think that if nothing is returned (null value), it should print “Missed” to the console. Obviously I messed up my logic somewhere, or perhaps I’m testing for the wrong thing?
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
// Check to see if the object was clicked
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit))
{
if(hit.transform !=null)
{
print(hit.transform);
//selected=false;
//iconQuad.renderer.material.mainTexture = offImage;
//renderer.material.color = offColor;
}
else if(hit.transform == null)
{
print("Missed");
}
}
}
}
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
// Check to see if the object was clicked
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit))
{
if(hit.transform !=null)
{
print(hit.transform);
//selected=false;
//iconQuad.renderer.material.mainTexture = offImage;
//renderer.material.color = offColor;
}
}
else
{
print("Missed");
}
}