#Object selector on OnMouseOver
1 messages · Page 1 of 1 (latest)
hi
public void OnMouseOver()
{
if (Input.touchCount > 0 && tap.trigger == true)
{
if (gm.letterCount == 0 && Tap.drop == false)
{
boxField.text += circleValue.GetComponent<TMPro.TextMeshProUGUI>().text;
boxFields[0].text = circleValue.text;
GM.playerGuess += circleValue.GetComponent<TMPro.TextMeshProUGUI>().text;
gm.letterCount++;
Debug.Log(GM.playerGuess);
GetComponent<Collider2D>().enabled = false;
}
}
}
}
thats what i had on the object, but i want to move it to another scirpt
why this code
why not using ray cast to get the selected object directly
idk whats that:(
raycast is a ray which gives which gameobject is chosen and you can get the data of that object over which the raycast hits
using things which my brain can think of
ray cast can also be controlled by mouse click
you dont need a void OnMouseDown
here first read how raycast works
i dont think if its that much hard to understand!
@molten bramble
??
thinking/ googling etc:D
why dont you ask me directly?
how to determine which object raycast will hit?
I know what you need cuz i was working on the same thing
mouse click
ray cast is just a ray
and if there is no mouse clicks exist?
it can return the gameobject on which the raycast hit
dont worry
on android touch one mouse click also work
if its zoom then individual touches are required
will it work if i want it to trigger all the time while player holds finger on the screen
hmmmmmmm
it will work like the object you click on
but you can modify it as you need
onmouseover was super neat way to do so
just attach script to an object and its ready pretty much
ray cast can work like this to return a game object you select
{
{
selectedObject = hit.transform.gameObject;
Debug.Log(selectedObject);
}
}```
here we got a ray and named its output as hit
now the selectedObject here is a public GameObject
Public GameObject selectedObject;
the gameobject can be setup as the object on which the ray cast hit
now you have the code on how to select the object
with raycast
but do you know how to set the direction of raycast with mouse click?
RaycastHit hit;
i forgot to mention the raycast lol
i will assume i have to put origin point
and from there it will draw a ray to my object?
go up with click
set the raycast direction on where you click
nope
raycast hits from your camera
you can also set its direction with mouse click
now think how?
vector
here this will help you
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
read and tell me when the guy wrote the raycast what it did next to get the input
nope
screen point to ray is to get the ray point emitted from the screen you have
like the camera
what did it do to get the direction of the raycast
here
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
(Input.mousePosition)
that,s the thing that specifies the direction of raycast
now assemble the code and make a script to select the gameobject with raycast
ye, i was writing about this line of code
lol
remember to write the function inside the void update()
if you get a little misunderstanding in writing the code then here is a hint
{
if (Input.GetMouseButtonDown(0))
{
///your method here
}
}```
show me your code when its done?
yep yep, figuring it out:)
try it
and ask me out if you need help in anything
sorry for my
it is my first time teaching a person like this lol
so i might be bad to let you understand things
so did you figure out a way to write the code @molten bramble
?
got this rn
cool
but you forgot one thing
do it in a mouse input
there is no thing like that
write it in this if statement
{
///your method here
}```
yea its good now
try it now
it will work now
but update void was more necessary to do it
to get the void work on every frame
anyways try it
it should work
it should
it works on an Update void
void Update() {}
hmmmmmm
hmmm maybe
try again or consult someone
cuz it works fine to me
did you us the script on camera or something else?
@molten bramble
use it on camera
due to this thing
Camera.main.ScreenPointToRay
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
now it will do things for you
😅 I got busy so i couldnt respond
or i should use 2d raycast)
2d raycast would create a image pixel over your canvas as well
so dont use that
but depends on your choice for what you need
anyways i am gonna leave this thread so bye!