Posts

Showing posts with the label destroy

apply force to objects within an area and other stuff

Bit of a messy example, but it demonstrates a few things in a simple way. 1 - finding the gameobjects that a collider is connected to 2 - finding the rigidbody component of said gameobject 3 - applying a force to rigidbody 4 - optional destroying gameobjects 5 - Oh and the "Physics Overlap Sphere" function. It returns all the colliders within a given spherical volume.   public void physicsSphereMake(Vector3 coord, float radius, float multiply)     {       //get an array of colliders within an overlap sphere that we provide position and radius for            Collider[] hitColliders = Physics.OverlapSphere(coord, radius);         //loop through array         foreach(var hitCollider in hitColliders)         {               //find out the game object   ...

"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...