I have a script that places blocks. But when I look down, it places one on the top of me. How to fix it?
using UnityEngine;
using System.Collections;
public class Build : MonoBehaviour
{
public GameObject prefabToCreate;
public Transform sillouetteTransform;
Vector3[] positions = new Vector3[256];
int currentArrayPos = 0;
Ray ray;
RaycastHit raycastHitInfo;
Vector3 placePos;
bool canBuild = true;
bool canShowSlt = true;
void FixedUpdate()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out raycastHitInfo, 10))
{
placePos = new Vector3(Mathf.Floor(raycastHitInfo.point.x), Mathf.Floor(raycastHitInfo.point.y), Mathf.Floor(raycastHitInfo.point.z));
for (int i = 0; i <= 255; i++)
{
if (positions *== placePos)*
{
canShowSlt = false;
break;
}
}
if (canShowSlt)
{
sillouetteTransform.gameObject.SetActive(true);
sillouetteTransform.position = placePos;
} else
{
canShowSlt = true;
sillouetteTransform.gameObject.SetActive(false);
}
if (Input.GetMouseButtonDown(1))
{
for (int i = 0; i <= 255; i++)
{
if (positions == placePos)
{
canBuild = false;
break;
}
}
if (currentArrayPos > 255)
{
canBuild = false;
}
if (canBuild)
{
Instantiate(prefabToCreate, placePos, new Quaternion());
positions[currentArrayPos] = placePos;
currentArrayPos += 1;
}
else
{
canBuild = true;
}
}
}
}
}
Also, there are other placement bugs.