generated from VR-Sexe/Unity3DTemplate
88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using Valve.VR.InteractionSystem;
|
|
|
|
public class Trash : MonoBehaviour
|
|
{
|
|
public GameObject largeFurnitureModel;
|
|
public int index;
|
|
private GameObject smallFurnitureModel;
|
|
private Vector3 returnPosition;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
returnPosition = transform.localPosition;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFurniture(GameObject furniture, float objectScale)
|
|
{
|
|
largeFurnitureModel = furniture;
|
|
smallFurnitureModel = Instantiate(furniture);
|
|
var throwables = smallFurnitureModel.GetComponentsInChildren<Throwable>();
|
|
foreach (Throwable throwable in throwables)
|
|
{
|
|
Destroy(throwable);
|
|
};
|
|
var rigidbodies = smallFurnitureModel.GetComponentsInChildren<Rigidbody>();
|
|
foreach (Rigidbody rigidbody in rigidbodies)
|
|
{
|
|
Destroy(rigidbody);
|
|
};
|
|
smallFurnitureModel.transform.parent = transform;
|
|
Destroy(smallFurnitureModel.GetComponent<MovableFurniture>());
|
|
Furniture objectBounds = smallFurnitureModel.AddComponent<Furniture>();
|
|
objectBounds.CalculateBounds();
|
|
var colldiers = smallFurnitureModel.GetComponentsInChildren<Collider>();
|
|
foreach (Collider collider in colldiers)
|
|
{
|
|
Destroy(collider);
|
|
};
|
|
float rescale = (objectScale / 1.4f) / objectBounds.combinedBounds.size.magnitude;
|
|
smallFurnitureModel.transform.localScale *= rescale;
|
|
smallFurnitureModel.transform.localPosition = Vector3.down * 0.2f;
|
|
|
|
StartCoroutine(KeepFurnitureAligned());
|
|
}
|
|
|
|
public void ClearFurniture()
|
|
{
|
|
Destroy(smallFurnitureModel);
|
|
}
|
|
|
|
private IEnumerator ReturnSphere()
|
|
{
|
|
float time = 0;
|
|
Vector3 startPosition = transform.localPosition;
|
|
while (time <= 1)
|
|
{
|
|
transform.localPosition = Vector3.Lerp(startPosition, returnPosition, time);
|
|
time += Time.deltaTime * 4;
|
|
yield return null;
|
|
}
|
|
yield break;
|
|
}
|
|
|
|
private IEnumerator KeepFurnitureAligned()
|
|
{
|
|
while (true)
|
|
{
|
|
smallFurnitureModel.transform.eulerAngles = new Vector3(0, smallFurnitureModel.transform.eulerAngles.y - (20 * Time.deltaTime), 0);
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
|
|
private void OnPointerEnter()
|
|
{
|
|
Debug.Log("enter");
|
|
}
|
|
}
|