Ok what i would like to know is how do you make a double click command. i have a orbit cam setup but i would like to use a double click to to set where to move to. i dont know how to register a double click.
also i would like to set up a right click comand that brings up a small window with some options depending on what you click on.
some of the options would be.
Go here
Set Hostile
Target
stuff like that. any examples will be great.
ok i figured out the double click thing i just dont know how to use it.
the scripting refrance isnt so spacific. any help or ideas would be great.
Good question, I think this might work.
var DoubleClickTime = 0.5;
var SingleClick = false;
function Update()
{
if(Input.GetButtonDown ("Fire1"))
{
SingleClick == true; // A single click has been commited
}
if(SingleClick == true) // If a single click
{
DoubleClickTime -= Time.deltaTime; // Decrement DoubleClickTime by the amount of time since last update
if(DoubleClickTime > 0 Input.GetButtonDown("Fire1"))// If DoubleClickTime hasn't run out and click is pressed
{
GoHere(
Input.GetAxis("MouseX"),
Input.GetAxis ("MouseY")); // Process double click
}
else
{
DoubleClickTime = 3.0; // Reset DoubleClickTime
SingleClick = false; // Reset SingleClick
}
}
}
function GoHere(var X, var Y)
{
//Move toward X,Y;
}
I’m in uni right now, so I haven’t tested this. It might need tweaking. I’m positive that you want to countdown from the first click, if the counter is zero by the time of the second click it doesn’t count. Altering the value of DoubleClickTime will allow for “lazier” double clicks with longer intervals in between.
If it doesn’t work, let me know and I’ll fix it when I get home.
im getting a few errors though im sure if i could figure out why the first one happens ill get rid of both of them.
Assets/spaceships/shipmovementscripts/large ship movement script/largeshipmovement.js(80,17): BCE0043: Unexpected token: var.
and
Assets/spaceships/shipmovementscripts/large ship movement script/largeshipmovement.js(80,21): BCE0044: expecting EOF, found ‘X’.
being new to scripting i have yet to figure out what these are. so ill tweak it till you can find a fix and if i figure it out then ill post as such.
change the function GoHere to this:
function GoHere(X,Y)
{
//Move toward X,Y;
}
Sorry, I don’t javascript very often.
now i get this.
Assets/spaceships/shipmovementscripts/large ship movement script/largeshipmovement.js(60,17): BCE0034: Expressions in statements must only be executed for their side-effects.
it could be that there is a comment making it’s way onto a line without a comment marker (“//”). Let me look at it when I get home.
ok now a question on raycasting.
do i acctualy need to hitsomething with my raycast to move my object to the location or can i just send it out into nowhere?
and how would i do it.
Are you working in 3d or 2d?
You can use Transform.LookAt to rotate your object towards the position of the mouse, and then use Transform.forward to move it forwards until it arrives there. Because you are translating from the mouse, you will probably need to use ScreenToWorldPoint, or ScreenPointToRay. All this new stuff can be daunting, I understand, but no one will do the work for you. I’ve spent many hours staring at computer screens, frustrated with video game development. Stick at it, though, and your hard work will be evident.
its not that i want you guys to do the work for me. if i wanted that id make a post in the collaberation page. when you guys do post code sure i use it but i also try to learn from it. being new to codeing like this but wanting to learn id rather you guys just point me in the right direction or if possible put some code up for example not exactly relateing to my project but just ingeneral. if i can see it i can tweak it. seeing as how the scripting resource doesnt have usage examples for alot of the stuff i want to do it sometimes gets hard to understand how to use it.
i really appreciate the help you have given me. you have helped me set up a base script for double clicking on something so thats a great start.
i only have alot of questions cause im new to it. after i start getting the hang of things ill be answering more then i ask. i also post all the code up after its working and give it to the comunity so even though i get help i try to give back as much as i can.
I’m the same, game development is a cruel (but rewarding) mistress. I was working on a 3d space flight game, but I abandoned it in the early stages. Maybe we could work together?