i,ve never worked with collider ray-casts before how would i go about setting it up?
I think it would help if i describe my situation a bit better: i have a minecraft-like game I,m trying to create the block placing system, i thought of the idea of creating a prefab(“BlockSensor”)with 6 planes on each side named “top” “left” “front” etc. i move this “BlockSensor” Prefab on whatever block the player is looking at and when right clicked it will create a block depending on which side your looking at, and this is how I,m doing it:
RaycastHit hit;
Ray CrosshairRay = new Ray(transform.position,transform.forward,1 << LayerMask.NameToLayer("Terrain"));
Debug.DrawRay (transform.position, transform.forward * PickUpDistance);
if (Physics.Raycast (CrosshairRay, out hit, PickUpDistance)) {
if(hit.collider.gameObject.tag == "Block")
CurrentBlockSensor.transform.position = new Vector3(hit.collider.gameObject.transform.position.x, hit.collider.gameObject.transform.position.y, hit.collider.gameObject.transform.position.z);
if(Input.GetMouseButtonDown(1)){
if(hit.collider.gameObject.name == "Top"){
Debug.Log("t");
Instantiate(Block,new Vector3(CurrentBlockSensor.transform.position.x,Mathf.RoundToInt(CurrentBlockSensor.transform.position.y) + 1,CurrentBlockSensor.transform.position.z),Quaternion.Euler(0,0,0));
}else if(hit.collider.gameObject.name == "Right"){
Debug.Log("r");
Instantiate(Block,new Vector3(CurrentBlockSensor.transform.position.x,CurrentBlockSensor.transform.position.y,Mathf.RoundToInt(CurrentBlockSensor.transform.position.z) + 1),Quaternion.Euler(0,0,0));
}else if(hit.collider.gameObject.name == "Left"){
Debug.Log("l");
Instantiate(Block,new Vector3(CurrentBlockSensor.transform.position.x,CurrentBlockSensor.transform.position.y,Mathf.RoundToInt(CurrentBlockSensor.transform.position.z) - 1),Quaternion.Euler(0,0,0));
}else if(hit.collider.gameObject.name == "Front"){
Debug.Log("f");
Instantiate(Block,new Vector3(Mathf.RoundToInt(CurrentBlockSensor.transform.position.x) + 1,CurrentBlockSensor.transform.position.y,CurrentBlockSensor.transform.position.z),Quaternion.Euler(0,0,0));
}else if(hit.collider.gameObject.name == "Back"){
Debug.Log("b");
Instantiate(Block,new Vector3(Mathf.RoundToInt(CurrentBlockSensor.transform.position.x) - 1,CurrentBlockSensor.transform.position.y,CurrentBlockSensor.transform.position.z),Quaternion.Euler(0,0,0));
}else if(hit.collider.gameObject.name == "Bottom"){
Debug.Log("bo");
Instantiate(Block,new Vector3(CurrentBlockSensor.transform.position.x,Mathf.RoundToInt(CurrentBlockSensor.transform.position.y) - 1,CurrentBlockSensor.transform.position.z),Quaternion.Euler(0,0,0));
}
//Instantiate(Block,new Vector3(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), Mathf.RoundToInt(position.z)), hit.collider.gameObject.transform.rotation);
}
if (hit.collider.tag == "Block") {
if(Input.GetMouseButton(0)){
Destroy(hit.collider.gameObject);
}
}
}