Add Bow and Arrow minigame, textmeshpro, lightprobes to door prefab

This commit is contained in:
Toomas Tamm
2021-02-13 22:21:22 +02:00
parent 7e547b0720
commit 13db3ea7f6
394 changed files with 21288 additions and 184 deletions

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Bow
{
public class ArcheryRange : MonoBehaviour
{
public Transform targetStartPosition;
public Transform targetEndPosition;
public GameObject targetPrefab;
public StartTarget startTarget;
public Vector3 minRandomOffset = new Vector3(0f, 0f, -5f);
public Vector3 maxRandomOffset = new Vector3(0f, 0f, 5f);
public float roundLength = 60f;
public float targetSpawnTime = 3f;
private List<ArcheryTarget> _targets;
private float _score;
private float _maxScore;
private float _roundEndTime;
private float _nextTargetTime;
private float _startEndDistance;
private bool _roundActive;
// Start is called before the first frame update
void Start()
{
_roundActive = false;
_targets = new List<ArcheryTarget>();
_score = 0;
_maxScore = 0;
_roundEndTime = 0f;
_startEndDistance = Vector3.Distance(targetStartPosition.position, targetEndPosition.position);
}
// Update is called once per frame
void Update()
{
if (!_roundActive) return;
if (Time.time >= _roundEndTime + roundLength)
{
Reset();
}
else
{
if (Time.time >= _nextTargetTime)
{
_nextTargetTime = Time.time + targetSpawnTime;
SpawnTarget();
}
}
}
private void SpawnTarget()
{
var randomPos = targetStartPosition.position + new Vector3(
Random.Range(minRandomOffset.x, maxRandomOffset.x),
Random.Range(minRandomOffset.y, maxRandomOffset.y), Random.Range(minRandomOffset.z, maxRandomOffset.z));
var prefab = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
prefab.transform.Rotate(new Vector3(0, -90, 0));
ArcheryTarget target = prefab.GetComponent<ArcheryTarget>();
target.endPosition = targetEndPosition.position;
target.archeryRange = this;
_targets.Add(target);
}
public void Reset()
{
foreach (var target in _targets.Where(target => target != null))
{
Destroy(target.gameObject);
}
_targets = new List<ArcheryTarget>();
if (_maxScore < _score) _maxScore = _score;
_score = 0;
Debug.Log(_maxScore);
startTarget.ShowTarget();
_roundActive = false;
}
public void StartRound()
{
_roundEndTime = Time.time + roundLength;
_nextTargetTime = Time.time;
_roundActive = true;
}
public void AddScore(float distance)
{
_score += _startEndDistance - (_startEndDistance - distance);
Debug.Log(_score);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 592ba278f86ebec478622d8cf05c309d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b311379c72a5ae4b8936e3b7283dd7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,6 +34,8 @@ namespace Bow
if (Physics.Linecast(_lastPosition, tip.position, out hit, LayerMask.GetMask("Default"),
QueryTriggerInteraction.Ignore))
{
hit.collider.gameObject.SendMessage("OnArrowHit", this,
SendMessageOptions.DontRequireReceiver);
Stop();
}
}
@@ -92,11 +94,16 @@ namespace Bow
{
base.OnSelectExited(interactor);
}
public new void OnSelectExiting(XRBaseInteractor interactor)
{
base.OnSelectExiting(interactor);
}
protected override void OnDestroy()
{
base.OnDestroy();
colliders.Clear();
}
}
}

View File

@@ -54,7 +54,6 @@ namespace Bow
_currentArrow.OnSelectExited(this);
base.OnSelectExiting(_currentArrow);
base.OnSelectExited(_currentArrow);
}
private void ReleaseArrow()

View File

@@ -0,0 +1,43 @@
using UnityEngine;
namespace Bow
{
public class StartTarget : MonoBehaviour
{
public ArcheryRange archeryRange;
public Canvas textCanvas;
private MeshRenderer _meshRenderer;
private BoxCollider _boxCollider;
// Start is called before the first frame update
void Start()
{
_meshRenderer = GetComponent<MeshRenderer>();
_boxCollider = GetComponent<BoxCollider>();
}
public void OnArrowHit(Arrow arrow)
{
if (arrow == null) return;
Destroy(arrow.gameObject);
HideTarget();
archeryRange.StartRound();
}
private void HideTarget()
{
_meshRenderer.enabled = false;
_boxCollider.enabled = false;
textCanvas.enabled = false;
}
public void ShowTarget()
{
_meshRenderer.enabled = true;
_boxCollider.enabled = true;
textCanvas.enabled = true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c25614c8b9ec3ef40963a7887bf26792
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: