56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
namespace WI
|
|
{
|
|
public class OrbitalControllerTarget : MonoBehaviour, ISingle
|
|
{
|
|
OrbitalController controller;
|
|
OrbitalControllerOption option;
|
|
|
|
public bool alwaysActive = false;
|
|
public bool active = false;
|
|
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
controller = FindSingle<OrbitalController>();
|
|
option = controller.option;
|
|
}
|
|
|
|
private void OnTriggerStay(Collider floorWall)
|
|
{
|
|
if (controller.viewMode != ViewMode.FirstPersonView)
|
|
return;
|
|
|
|
SetPosToOutsideWall(floorWall);
|
|
}
|
|
|
|
void SetPosToOutsideWall(Collider floorWall)
|
|
{
|
|
if (floorWall.gameObject.layer.Equals(LayerMask.NameToLayer("Floor Wall")))
|
|
{
|
|
Vector3 hitCenter = floorWall.bounds.center;
|
|
float sizeX = floorWall.bounds.size.x;
|
|
float sizeZ = floorWall.bounds.size.z;
|
|
|
|
Vector3 vectorPoint = Vector3.zero;
|
|
|
|
if (sizeX > sizeZ)
|
|
{
|
|
vectorPoint = new Vector3(transform.position.x, transform.position.y, hitCenter.z);
|
|
}
|
|
else
|
|
{
|
|
vectorPoint = new Vector3(hitCenter.x, transform.position.y, transform.position.z);
|
|
}
|
|
|
|
Vector3 direction = transform.position - vectorPoint;
|
|
float radius = GetComponent<SphereCollider>().radius;
|
|
|
|
transform.position += direction * radius;
|
|
}
|
|
}
|
|
}
|
|
} |