now im making a top down game and i want to add laser i wrote this code , no errors but its not working can anyone help me
using UnityEngine;
public class vector3example : MonoBehaviour
{
Ray ray1;
public RaycastHit hit1;
[SerializeField] private Vector3 startpoint;
[SerializeField] private Vector3 endpoint;
public GameObject player1;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Physics.Linecast(startpoint, endpoint,out hit1))
{
if(hit1.collider.tag == "player")
{
Destroy(player1);
}
}
}
}
Sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
If you learn more about the problem, here is…
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see
links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
Welcome! I’ve been here a long time and I still write bugs all the time.
And I still use the same techniques outlined above. They’re not even Unity-related really, just universal troubleshooting steps, tuned to the things you need to look for in code.
The good news is after you’ve fixed 10,000 or more bugs you will begin to notice patterns that help you do it faster.