topical media & game development

talk show tell print

lib-unity-tutorial-m2h-2-Assets-Game-5-Shooting-gallery-Scripts-PlayerInput.cs / cs



  using UnityEngine;
  using System.Collections;
  
  public class PlayerInput : MonoBehaviour {
  
      public AudioClip canHitSound;
  
          void Update () {        
          if(Input.GetMouseButtonDown(0)){
              Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
              RaycastHit hit;
              if (Physics.Raycast (ray, out hit, 100)) {
  
                  Debug.DrawLine (ray.origin, hit.point);
  
                  if (hit.transform.tag == "ShootingObject")
                  {
                      audio.pitch = Random.Range(0.9f, 1.3f);
                      audio.Play();
                      GameManager.SP.RemoveObject(hit.transform);
                  }else if(hit.transform.tag == "Can"){
                      audio.PlayOneShot(canHitSound);
  
                      Vector3 explosionPos = transform.position;
                      hit.rigidbody.AddExplosionForce(5000, explosionPos, 25.0f, 1.0f);
                  }
  
              }
          }
          }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.