Phillipes_Fablab/Assets/Scripts/MovableFurniture.cs
2023-01-10 17:09:03 +01:00

74 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class MovableFurniture : MonoBehaviour
{
private List<Transform> children;
private List<ObjectOutline> outlines;
private Rigidbody _rigidbody;
// Start is called before the first frame update
void Start()
{
_rigidbody = GetComponent<Rigidbody>();
children = new List<Transform>(GetComponentsInChildren<Transform>());
outlines = new List<ObjectOutline>();
foreach (Transform child in children)
{
var part = child.gameObject.AddComponent<MovableFurniturePart>();
part.parent = this;
var outline = child.gameObject.AddComponent<ObjectOutline>();
outlines.Add(outline);
outline.OutlineMode = ObjectOutline.Mode.OutlineAll;
outline.OutlineColor = Color.yellow;
outline.OutlineWidth = 5f;
outline.enabled = false;
}
}
// Update is called once per frame
void Update()
{
}
public void OnPointerClickUp()
{
if (_rigidbody != null)
{
_rigidbody.useGravity = true;
}
}
public void OnPointerClickDown()
{
if(_rigidbody!= null)
{
_rigidbody.useGravity= false;
}
}
public void OnPointerEnter()
{
foreach (ObjectOutline outline in outlines)
{
/*child.OutlineMode = ObjectOutline.Mode.OutlineAll;
child.OutlineColor = Color.yellow;
child.OutlineWidth = 5f;*/
outline.enabled = true;
}
}
public void OnPointerExit()
{
foreach (ObjectOutline outline in outlines)
{
outline.enabled = false;
}
}
}