im working on a building system and need to get the y pos of the floor object that im “snapping on to”
heres my code any help is appreciated.
the parts with case “(collider name)” is what i need help with.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CardboardFloorCollider : MonoBehaviour {
CardBoardFloor CardBoardFloorScript;
Vector3 SizeOfCardBoardFloor;
// Use this for initialization
void Start () {
CardBoardFloorScript = transform.parent.parent.GetComponent<CardBoardFloor>();
SizeOfCardBoardFloor = transform.parent.parent.GetComponent<Collider>().bounds.size;
}
// Update is called once per frame
void Update()
{
}
//Snapping abillity
void OnTriggerEnter(Collider other){
if (BuildingManager.IsBuilding && other.tag == "CardBoardFloor" && CardBoardFloorScript.IsPlaced && !other.GetComponent<CardBoardFloor>().IsSnapped) {
other.GetComponent<CardBoardFloor>().IsSnapped = true;
float SizeX = SizeOfCardBoardFloor.x;
float SizeZ = SizeOfCardBoardFloor.z;
switch(this.transform.tag)
{
case "WestCollider":
other.transform.position = new Vector3(transform.parent.parent.position.x - SizeX, ?, transform.parent.position.z);
break;
case "EastCollider":
other.transform.position = new Vector3(transform.parent.parent.position.x + SizeX, ?, transform.parent.position.z);
break;
case "NorthCollider":
other.transform.position = new Vector3(transform.parent.parent.position.x, ?, transform.parent.position.z + SizeZ);
break;
case "SouthCollider":
other.transform.position = new Vector3(transform.parent.parent.position.x, ?, transform.parent.position.z - SizeZ);
break;
}
}
}
}