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))
- {
- GameObject hitObject = hit.transform.gameObject;
- Debug.Log(hitObject);
- //ReactiveTarget target = hitObject.GetComponent<ReactiveTarget>();
- StartCoroutine(ShpereIndicator(hit.point));
- StartCoroutine(HitObject(hitObject));
- }
- }
- }
- 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);
- }
- private IEnumerator HitObject(GameObject target)
- {
- target.transform.Rotate(-75, 0, 0);
- yield return new WaitForSeconds(1.5f);
- Destroy(target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement