61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ContactArea : MonoBehaviour
|
||
|
{
|
||
|
public Buildings buildings;
|
||
|
public bool isCountacting;
|
||
|
public RectTransform panel;
|
||
|
private float panel_InitHeight;
|
||
|
private float self_InitHeight;
|
||
|
private void Start()
|
||
|
{
|
||
|
isCountacting = false;
|
||
|
buildings = transform.parent.GetComponent<Buildings>();
|
||
|
|
||
|
panel_InitHeight = panel.GetHeight();
|
||
|
self_InitHeight = transform.Find("Area2").GetComponent<BoxCollider>().size.y;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
|
RaycastHit hit;
|
||
|
|
||
|
if (Physics.Raycast(ray, out hit, 8f))
|
||
|
{
|
||
|
if (hit.transform.parent == transform)
|
||
|
{
|
||
|
if (!isCountacting)
|
||
|
{
|
||
|
isCountacting = true;
|
||
|
buildings.ContactBuildingsArea();
|
||
|
transform.Find("Area2").gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (isCountacting)
|
||
|
{
|
||
|
isCountacting = false;
|
||
|
buildings.ExitBuildingsArea();
|
||
|
transform.Find("Area2").gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
float deno = (panel.GetHeight() - panel_InitHeight)/116;
|
||
|
transform.Find("Area2").GetComponent<BoxCollider>().size = new Vector3(transform.Find("Area2").GetComponent<BoxCollider>().size.x, self_InitHeight+deno*1.8f, transform.Find("Area2").GetComponent<BoxCollider>().size.z);
|
||
|
transform.Find("Area2").GetComponent<BoxCollider>().center = new Vector3(transform.Find("Area2").GetComponent<BoxCollider>().center.x, deno * 0.9f, transform.Find("Area2").GetComponent<BoxCollider>().center.z);
|
||
|
}
|
||
|
private void OnMouseEnter()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void OnMouseExit()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|