Advertisement
sphinx2001

Shoot version 0.1

Mar 7th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 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.                 StartCoroutine(ShpereIndicator(hit.point));
  26.             }
  27.         }
  28.     }
  29.     private IEnumerator ShpereIndicator(Vector3 pos)
  30.     {
  31.         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  32.         sphere.transform.position = pos;
  33.         sphere.transform.localScale = new Vector3(2.5f, 0.5f, 2.5f);
  34.         yield return new WaitForSeconds(1);
  35.         Destroy(sphere);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement