Files
FebGameJam/Assets/Scripts/UpdatedWallTrigger.cs
T
2022-02-26 18:45:46 -06:00

74 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UpdatedWallTrigger : MonoBehaviour
{
public RaycastHit2D hit;
public Ray ray;
private LayerMask layerMask;
private float angleStep = 8;
public Transform target;
[Range (1f,10f)]public float rayLength = 10f;
public BoxCollider2D box;
public GameObject camMove;
public GameObject catMove;
private int counter = 0;
// Start is called before the first frame update
void Start()
{
layerMask = LayerMask.GetMask("Player");
}
// Update is called once per frame
void Update()
{
for (int i = 1; i <= angleStep; i++)
{
var rayAngle = Quaternion.AngleAxis((360f / angleStep) * i, target.forward) * Vector3.left;
hit = Physics2D.Raycast(target.position, rayAngle, rayLength, layerMask);
float xe = Mathf.Abs(hit.point.x - target.localPosition.x);
float ye = Mathf.Abs(hit.point.y - target.position.y);
float goalx = Mathf.Abs(target.position.x * box.size.x) ;
float goaly = Mathf.Abs(target.position.x * box.size.x);
if (hit && counter >=150)
{
if (xe >= 44 && xe <50)
{
/*Debug.Log("Counter Right "+counter);
Debug.Log("XE " + xe);
Debug.Log("Goaly " + goaly);
Debug.Log(target.position.y * box.size.y);*/
camMove.transform.position = new Vector3(camMove.transform.position.x + 22f, camMove.transform.position.y, -1.3f);
catMove.transform.position = new Vector3(catMove.transform.position.x + 10f, catMove.transform.position.y+1f, 0);
xe = 0;
ye = 0;
goalx = 0;
goaly = 0;
counter = 0;
}
else if (xe >=50)
{
/*Debug.Log("Counter Left " + counter);
Debug.Log("XE "+ye);
Debug.Log("Goaly "+ goaly);*/
camMove.transform.position = new Vector3(camMove.transform.position.x - 22f, catMove.transform.position.y + 1.0f,-1.3f);
catMove.transform.position = new Vector3(catMove.transform.position.x - 10f, catMove.transform.position.y ,0);
counter = 0;
xe = 0;
ye = 0;
goalx = 0;
goaly = 0;
}
}
counter++;
}
void OnTriggerEnter2D(Collider2D col)
{
}
}
}