I press left mouse button and it shows me what the raycast hit twice instead of once. How to make it show just once?
Then the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldInteraction : MonoBehaviour {
public float maxDistance = 5f;
void FixedUpdate () {
if(Input.GetMouseButtonDown(0))
{
Ray newray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit newhit;
Debug.DrawLine(transform.position, transform.position + Vector3.forward * maxDistance, Color.red);
if(Physics.Raycast(newray, out newhit, maxDistance))
{
if (newhit.collider.gameObject.name != "Ground")
{
Debug.Log("You shot a " + newhit.collider.gameObject.name);
}
}
}
}
}