Posts

Showing posts with the label mouse

Compute Shaders, a basic particle system drawn with a vertex fragment shader

A post for reference really... Not a lot of magic here - except we're using a Graphic procedural - a point- to draw particles. To do this we calculate the position of the particles in the compute shader, then a standard vert-frag shader assigned to a material reads from the gpu buffer and draws the points accordingly. We're also getting the mouse position on screen converted to World Space & having the particles follow that coordinate.  The C# is as follows, careful with the comments i've left...blogger's formatting is a bit wonky - using System.Collections; using System.Collections.Generic; using UnityEngine; #pragma warning disable 0649 public class particle_dave : MonoBehaviour {     private Vector2 cursorPos;     // struct of a particle, fairly simple attributes     struct Particle     {         public Vector3 position;         public Vector3 vel...

"on click" basics

From the Unity pages, a simple way to detect your mouse clicks - using UnityEngine; using System.Collections; // Detects clicks from the mouse and prints a message // depending on the click detected. public class ExampleClass : MonoBehaviour { void Update () { if ( Input.GetMouseButtonDown (0)) Debug.Log ("Pressed primary button."); if ( Input.GetMouseButtonDown (1)) Debug.Log ("Pressed secondary button."); if ( Input.GetMouseButtonDown (2)) Debug.Log ("Pressed middle click."); } }    And from this site - void Update ( ) { if ( Input . GetMouseButtonDown ( 0 ) )        {      Ray ray = Camera . main . ScreenPointToRay ( Input . mousePosition ) ;      RaycastHit hit ;      if ( Physics . Raycast ( ray , out hit ) )             {           Destroy ( h...