31 lines
806 B
C#
31 lines
806 B
C#
using UnityEngine;
|
|
|
|
namespace Bow
|
|
{
|
|
public class ArcheryTarget : MonoBehaviour
|
|
{
|
|
public Vector3 endPosition;
|
|
public float forwardSpeed = 2f;
|
|
public ArcheryRange archeryRange;
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
float step = forwardSpeed * Time.deltaTime;
|
|
|
|
var position = transform.position;
|
|
transform.position = Vector3.MoveTowards(position,
|
|
new Vector3(endPosition.x, position.y, position.z), step);
|
|
}
|
|
|
|
|
|
public void OnArrowHit(Arrow arrow)
|
|
{
|
|
if (arrow == null) return;
|
|
|
|
archeryRange.AddScore(Vector3.Distance(transform.position, endPosition));
|
|
Destroy(arrow.gameObject);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |