- Home /
Mouse follow performance in iPhone
Hi guys!
I want to make a game object to follow my mouse pointer and it's working perfectly in desktop however in iPhone the object movement is delayed. I assume it's because of the processing power and probably my method is not suitable for iPhone, I'm not really sure. So far, here is the script for mouse follow.
private var depth : float;
private var count : int;
private var touch : Touch;
private var wantedPos : Vector3;
function Awake(){
this.renderer.enabled = false;
depth = 10;
}
InvokeRepeating("FollowMouse", 0, 0.1);
function FollowMouse(){
count = Input.touchCount;
touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Moved){
wantedPos = Camera.main.ScreenToWorldPoint(touch.position);
transform.position = wantedPos;
}
}
If in iPhone, the game object is a bit late so it's following behind the touch position while in desktop, the game object can perfectly follow the mouse location. Thanks in advance! =)
EDIT: Changed from using mouse input to touch input.
Answer by Kiloblargh · Mar 27, 2012 at 03:56 AM
Why is "this.renderer.enabled = false" in Update, rather than Awake? Also, never declare variables in Update. Declare them at the start of the script and include types. If it's still too slow, replace Update with an InvokeRepeating that goes 15 times a second or so.
You shouldn't be using anything "mouse" related on the iPhone anyway. It will probably stop working in an upcoming version of iOS or Unity.
http://unity3d.com/support/documentation/ScriptReference/Input.GetTouch.html
Ok, I've changed from using mouse input to touch input but it's still the same result. I tried using Update() but it's still the same so I changed to InvokeRepeating() but it's the same as well. Does the point conversion Camera.main.ScreenToWorldPoint
has anything to do with performance?