This function is used for UI buttons mostly but sometimes we need it in game specs. It is implemented easily with mouse enter-exit listeners. We can change color of an object with renderers. Create a cube object and attach this script to it. At first, define 2 colors for standard […]
object
Drag Object with Mouse – Unity3D (C#) It’s too easy and quick to drag an object with mouse. Just use OnMouseDown() and OnMouseDrag() functions. private Vector3 screenPoint; private Vector3 offset; void OnMouseDown(){ screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); } void OnMouseDrag(){ Vector3 cursorPoint = new […]
Drag Object with Mouse – Unity3D (C#)
Move Object with Lerp – Unity3D (C#) You can use Lerp function to move an object automatically. You just need start and end points. Object moves from start to end in time. You can assign start point and end point manually in script or with mouse click. These points may […]
Move Object with Lerp – Unity3D (C#)
Mouse Click on Game Object – Unity3D (C#) There are two ways to perform click function on a game object: 1- Create and attach a script to the target object. Write this function in it. void OnMouseDown(){ Destroy(gameObject); } 2- You can use Physics.Raycast to detect target with ray. […]
Mouse Click on Game Object – Unity3D (C#)
Character Control with Keyboard – Unity3D (C#) I will show you 2 ways to move your character with keyboard. Create a cube named “Char” and create a script named “Movement”. You can attach this script to Char object but we won’t. Lets create an object before Start() function: public GameObject character; […]
