I have a script that projects a ray to the ground layer from the mouse to show where an object is about to be placed. Its a city builder thats supposed to show an outline of a house before its placed. The outline is just a prefab with a transparent material.
When the prefab is moving with the mouse (about to be placed) it shakes about and I can't figure out why. Anyone know how to fix this?
Also layer 8 is the ground.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlueprintScript : MonoBehaviour
{
RaycastHit hit;
Vector3 movePoint;
public GameObject prefab;
void Start()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 50000.0f, (1 << 8)))
{
transform.position = hit.point;
}
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 50000.0f, (1 << 8)))
{
transform.position = hit.point;
}
if (Input.GetMouseButton(0))
{
Instantiate(prefab, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}