- Home /
Move Camera According to Mouse Movement While Button is Pressed
I have looked all around and I can't seem to find out how to do this. Basically, what I want is to have the camera pan while the middle mouse button is pressed. For example, like Starcraft 2: you press the middle mouse button and drag the mouse upwards, then the camera will move upwards.
If anybody can help me, that would be greatly appreciated! And preferably with Unityscript, not C#.
Thanks!
Comment
Answer by goo-muffin · Dec 31, 2012 at 12:23 PM
take the pre made camera orbit script and then active it with
function Update(){
if(mouseOver(Rect(/*The Rect of your Button*/)){
if(Input.GetKeyDown("mouse 0") || Input.GetKeyDown("mouse 1")){
var scriptname : ScriptName = Whatever.GetComponent("ScriptName");
scriptname.active = true;
}else{
var scriptname : ScriptName = Whatever.GetComponent("ScriptName");
scriptname.active = false;
}
}else{
var scriptname : ScriptName = Whatever.GetComponent("ScriptName");
scriptname.active = false;
}
}
function mouseOver(rect :Rect){
if(Input.mousePosition.x >= rect.x && Input.mousePosition.x <= rect.x + rect.width){
if(Screen.height - Input.mousePosition.y >= rect.y && Screen.height - Input.mousePosition.y <= rect.y + rect.height){
return true;
}
}else{
return false;
}
}
Your answer
Follow this Question
Related Questions
Mouse Follow Script Help 1 Answer
Camera Movement issue 1 Answer
Select/Drag/Drop Objects with a mouse 0 Answers
Move the camera when the mouse reaches the edges of the screen 1 Answer
3D RTS camera 3 Answers