[TASK] Working on duck-catching minigame
This commit is contained in:
46
Assets/FloatingDuckController.cs
Normal file
46
Assets/FloatingDuckController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FloatingDuckController : MonoBehaviour
|
||||
{
|
||||
public Vector3 initialForce = new Vector3(-100, 0, 0);
|
||||
public float minimumVelocity = 3;
|
||||
|
||||
public Collider duckCaughtCollider;
|
||||
|
||||
public event EventHandler DuckCaught;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_rigidbody.velocity = Vector3.zero;
|
||||
_rigidbody.AddForce(initialForce);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_rigidbody.velocity.magnitude < minimumVelocity)
|
||||
{
|
||||
_rigidbody.velocity = _rigidbody.velocity.normalized * minimumVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other == duckCaughtCollider)
|
||||
{
|
||||
if (DuckCaught != null)
|
||||
{
|
||||
DuckCaught.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user