quality-control/Assets/Scripts/Machines/ProductSpawner.cs

37 lines
1.2 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using UnityEngine;
public class ProductSpawner: MonoBehaviour
{
public List<Transform> PossibleOrientations;
public Vector2 yRotation;
2024-08-18 20:01:15 +00:00
2024-08-19 21:43:05 +00:00
public AudioClip spawnClip;
public void SpawnProduct(ProductType type)
2024-08-18 20:01:15 +00:00
{
var randomIndex = Random.Range(0, PossibleOrientations.Count);
var randomOrientation = PossibleOrientations[randomIndex];
var rotation = Quaternion.AngleAxis(Random.Range(yRotation.x, yRotation.y), Vector3.up) *
randomOrientation.rotation;
ProductType.SpawnProduct(type, transform, randomOrientation.position, rotation);
2024-08-19 22:31:38 +00:00
if (spawnClip)
{
NAudio.Play(spawnClip, transform.position);
}
}
2024-08-18 22:26:03 +00:00
public void SpawnProduct(ProductType type, DefectType defect)
{
var randomIndex = Random.Range(0, PossibleOrientations.Count);
var randomOrientation = PossibleOrientations[randomIndex];
var rotation = Quaternion.AngleAxis(Random.Range(yRotation.x, yRotation.y), Vector3.up) *
randomOrientation.rotation;
ProductType.SpawnProduct(type, defect, transform, randomOrientation.position, rotation);
}
}