so i know i should write something to send out the job to the new script.
let new script to do the things and send it back to this script.
and i wanna to know how should i write?
Here is my script. can you show me a example.
and also about the GetComponent, is it only the only cube(object) or all Obj in the tag can work on it?
private float range = 5;
public delegate void ClickAction();
public static event ClickAction OnClicked;
private void Update()
{
Vector3 direction = Vector3.forward;
Ray ray = new Ray(transform.position, transform.TransformDirection(direction * range));
Debug.DrawRay(transform.position, transform.TransformDirection(direction * range));
if (Physics.Raycast(ray, out RaycastHit hit, range))
{
if (hit.collider.CompareTag("movecube"))
{
print("found it Its movecube");
if (Input.GetMouseButtonDown(0))
{
print("do the event thing");
}
}
}
}
Rather than me play 21 questions about how your scene is set up, why don’t you start with some basic Youtube tutorials on this stuff instead!
If you can’t get it from the tutorials, you certainly won’t get it from this little text box. It will NOT all be code that you must consider.
The purpose of this forum is to assist people who are ready to learn by doing, and who are unafraid to get their hands dirty learning how to code, particularly in the context of Unity3D.
This assumes you have at least written and studied some code and have run into some kind of issue.
If you haven’t even started yet, go check out some Youtube videos for whatever game design you have in mind. There are already many examples of the individual parts and concepts involved, as there is nothing truly new under the sun.
If you just want someone to do it for you, you need go to one of these places:
You have this backwards. FIRST you check for Input and THEN you check what to do with that Input. The raycast is far more expensive than checking if the mouse button is down. If it isn’t, there’s no need to do any raycasting.
Moreover, this structure will lead to injecting input tests deep inside your code and likely duplicate them. But the state of input isn’t going to change over the course of a frame. If you ever find yourself writing a line that tests for the exact same input AGAIN you know this needs to be changed to test the input first and use the input state in all other places.
Whatever input you contemplate, make temporary variables to hold it.
private Vector2 movement;
private bool jump;
Now in your Update() loop:
void Update()
{
// clear input
movement = Vector2.zero;
jump = false;
// gather input
movement += new Vector2 (Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (Input.GetKeyDown( KeyCode.Space))
{
jump = true;
}
// TODO: any other input: touch, joystick, kinect, etc.
// TODO: act ONLY on the movement and jump variables, never again touching the actual input system this frame
}
Now Unity comes along and has a “New Input system” that you have to use.
ok. raycast no need alway here. got it. i will change it click first then raycast then the transform.
i had ask someone on discord he said i can actually to code the tramsform part in same script on update.
so i guess i just not do the send out script part.
all i do this project is want do test is tranform work or not so this part i try it my self so.
if no need to do send out i guess i just skip the unknow part.