Advertisement
sphinx2001

Shoter v 0.2

Mar 7th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Shoot : MonoBehaviour
  6. {
  7.     private Camera _camera;
  8.     // Start is called before the first frame update
  9.     void Start()
  10.     {
  11.         _camera = GetComponent<Camera>();
  12.     }
  13.  
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.         if (Input.GetMouseButtonDown(0))
  18.         {
  19.             Vector3 point = new Vector3(_camera.pixelWidth /
  20.                 2, _camera.pixelHeight / 2, 0);
  21.             Ray ray = _camera.ScreenPointToRay(point);
  22.             RaycastHit hit;
  23.             if(Physics.Raycast(ray,out hit))
  24.             {
  25.                 GameObject hitObject = hit.transform.gameObject;
  26.                 Debug.Log(hitObject);
  27.                 //ReactiveTarget target = hitObject.GetComponent<ReactiveTarget>();
  28.                 StartCoroutine(ShpereIndicator(hit.point));
  29.                 StartCoroutine(HitObject(hitObject));
  30.             }
  31.         }
  32.     }
  33.     private IEnumerator ShpereIndicator(Vector3 pos)
  34.     {
  35.         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  36.         sphere.transform.position = pos;
  37.         sphere.transform.localScale = new Vector3(2.5f, 0.5f, 2.5f);
  38.         yield return new WaitForSeconds(1);
  39.         Destroy(sphere);
  40.     }
  41.  
  42.     private IEnumerator HitObject(GameObject target)
  43.     {
  44.         target.transform.Rotate(-75, 0, 0);
  45.         yield return new WaitForSeconds(1.5f);
  46.         Destroy(target);
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement