Just a note, throw pillows barley matter, that is just bad comedy.
I have a script to highlight game objects with a selectable tag, and the length is set to 5 units. The raycast works with every object with a selectable tag except for a throw pillow. The pillow has a mesh collider, mesh renderer, and has the tag selectable. Here is my script, an image showing the raycast intersecting, and an image showing the inspector tab for my pillow.
Also, if anyone has suggestions on how to better format pictures on this forum, please let me know.
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
public class Select : MonoBehaviour
{
[SerializeField] private string selectableTag = "Selectable";
[SerializeField] private Material HighlightMat;
public int Lentgh;
private Material NormalMat;
public Camera cam;
private Transform _selection;
void Update()
{
// Deselect object
if (_selection != null) // see if the selection is null or not
{
var selectionRender = _selection.GetComponent<Renderer>(); // get renderer component
selectionRender.material = NormalMat;
_selection = null;
}
Vector3 point = new Vector3(cam.pixelWidth / 2, cam.pixelHeight / 2, 0);
var ray = Camera.main.ScreenPointToRay(point);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Lentgh)) // Change the raycast length to Lentgh
{
Debug.DrawRay(ray.origin, ray.direction * Lentgh, Color.yellow); // Draw the ray in the Scene view
var selection = hit.transform; // find what object was hit
if (selection.CompareTag(selectableTag)) // is it selectable?
{
var selectionRender = selection.GetComponent<Renderer>(); // get renderer component
NormalMat = selectionRender.material;
if (selectionRender != null)
{
selectionRender.material = HighlightMat; //highlight it with the material
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Maybe this wont suck?");
}
}
_selection = selection;
}
}
}
}