[TASK] Spawn collectable ducks on the map when in range

This commit is contained in:
2019-08-19 00:36:56 +02:00
parent 98219ecfef
commit 279c5fbbbe
2270 changed files with 6269477 additions and 182 deletions

29
Assets/CollectableDuck.cs Normal file
View 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");
}
}
}
}