C# OnMouseDown in Unity! - Beginner Scripting Tutorial

C# OnMouseDown in Unity! - Beginner Scripting Tutorial

Unity

4 года назад

69,013 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Sudarsan Sahoo
Sudarsan Sahoo - 30.04.2023 18:16

Thanks

Ответить
adam
adam - 01.11.2021 19:33

Can this method be used universally with if statements for doing stuff click on any object w ith a rigidbody or only the objects this script is attached to? What a stupidly short tutorial short tutorials like these waste more of peoples time trying to figure stuff out than it saves

Ответить
JOSH BASADRE
JOSH BASADRE - 30.12.2020 16:07

i think the problem with the tutorial is that you use things outsikde the tutorial sobject or in other words insert something thaty is not teached from the subject you are talking about so yeah i hbope you make a new tutorial series but actually helpful

Ответить
Tony Lovell
Tony Lovell - 29.09.2020 16:53

These videos never seem to spell out all that is actually required for their functionality to work. Here, the GameObject clicked on needs to have a collider whose isTrigger=true, Physics.queriesHitTriggers must be set to true, and the item clicked on needs a RigidBody. Also, this seems like a missed opportunity to discuss questions of what happens if multiple items are under the mouse, how to precude "clicking through walls", etc

Ответить
JS
JS - 20.07.2020 16:54

Why it is not inside the update()?

Ответить
Bii
Bii - 23.06.2020 20:42

Doesn't work on 2d, does it only work on 3d collieers

Ответить
Jimmy Hill
Jimmy Hill - 20.05.2020 12:31

Is there a way of setting a maximum distance from the object when clicking? For example using an FPS controller, you could use this script to open a door, but without a range check you'd be able to open the door from far away.
Any help appreciated.

Ответить
Raven Felman
Raven Felman - 30.10.2019 18:47

I have a question: there is any function that detects if the click of the mouse occurs outside of the object?

Ответить
Gregory Fenn
Gregory Fenn - 03.08.2019 23:41

I've been using Unity for 2 years and never new about OnMouseDown, OnMouseEnter, OnMouseExit as special functions. I was always using some kind of Camera Raycast through mouse to hit colliders to run any functionality, but this is 100x easier! If anyone wants to test it out, you can use the following code as a component of a 3D collider (like a default cube or sphere) and play with it in a new unity project:

public class MouseAction : UnityEngine.MonoBehaviour
{
void OnMouseDown()
{
transform.position += UnityEngine.Vector3.right;
}

void OnMouseExit()
{
transform.localScale *= 0.5f;
}

void OnMouseEnter()
{
transform.localScale *= 2;
}
}

Ответить
Pierce Zaman
Pierce Zaman - 28.07.2019 15:29

its been years since I've looked at anything programming but here I am at 5:30 am lol

Ответить
Vaust XIII
Vaust XIII - 27.07.2019 10:53

What is the diffrence between OnMouseDown and Raycasting from screen click position? Perfomance?

Ответить
Devante Hines
Devante Hines - 26.07.2019 20:47

Nice when I get my new laptop Amma try these stuffs

Ответить
Kenny Meesters
Kenny Meesters - 26.07.2019 20:04

Is der also a more aesy way to make phone games

Ответить
Omar Alkaley
Omar Alkaley - 10.07.2019 03:25

Please what is the difference between transform.forward and Vector3.forward?

Ответить