[TASK] Spawn collectable ducks on the map when in range
This commit is contained in:
29
Assets/CollectableDuck.cs
Normal file
29
Assets/CollectableDuck.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class CollectableDuck: MonoBehaviour
|
||||
{
|
||||
private Camera _camera;
|
||||
private Collider _collider;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
_collider = GetComponent<Collider>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
var ray = _camera.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;;
|
||||
if (Physics.Raycast(ray, out hit) && hit.collider == _collider)
|
||||
{
|
||||
Debug.Log("Tapped a ducky");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user