Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Shoot : MonoBehaviour
- {
- private Camera _camera;
- // Start is called before the first frame update
- void Start()
- {
- _camera = GetComponent<Camera>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- Vector3 point = new Vector3(_camera.pixelWidth /
- 2, _camera.pixelHeight / 2, 0);
- Ray ray = _camera.ScreenPointToRay(point);
- RaycastHit hit;
- if(Physics.Raycast(ray,out hit))
- {
- StartCoroutine(ShpereIndicator(hit.point));
- }
- }
- }
- private IEnumerator ShpereIndicator(Vector3 pos)
- {
- GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- sphere.transform.position = pos;
- sphere.transform.localScale = new Vector3(2.5f, 0.5f, 2.5f);
- yield return new WaitForSeconds(1);
- Destroy(sphere);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement