x


Problem with Input.GetMouseButtonDown? weird bug. C#

This is very odd!

I have a code block that looks like this:

if (Input.GetMouseButtonDown(0))
{
  DoSomething();

  int value = 0;
}

It's in the Update() function of a script attached to a prefab.

If I create a copy of the prefab at runtime. There's no problem. DoSomething is called when the mouse is clicked.

If I have a prefab in the scene, click play, then step through in the debugger and click on the mouse, I can see that the execution steps into the block but DoSomething is not called and execution falls through to "int value = 0;"

The code then continues as expected. No exceptions are thrown. Nothing seems amiss.

Anyone know why this might be happening?

(if I replace Input.GetMouseButtonDown with any other true statement then DoSomething is called fine)

more ▼

asked Jul 08 '11 at 11:59 AM

mat gravatar image

mat
126 19 20 25

if all you say here is true then I cannot see any error on your part. I'd file a bug report.

Jul 08 '11 at 01:05 PM Joshua

When you it falls to int value=0; I would want to take a look at "DoSomething()". Could it be that the function is initiated only when prefab instantiates?

Jul 08 '11 at 01:35 PM Kourosh

He said that if he replaced the if statement with a true statement it works fine. All I can think of is that the mouseButtonDown messes something inside the DoSomething() method

Jul 08 '11 at 01:37 PM Joshua

DoSomething could be just an empty function...

Jul 08 '11 at 04:53 PM mat
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I have found that if

more ▼

answered Aug 05 '11 at 10:03 PM

atski gravatar image

atski
1

(comments are locked)
10|3000 characters needed characters left

I have found weird issue, if scene has no camera tagged "MainCamera" (so Camera.main is always null) my mouse events doesn't work at all.

more ▼

answered Aug 05 '11 at 10:07 PM

atski gravatar image

atski
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x10
x1

asked: Jul 08 '11 at 11:59 AM

Seen: 1229 times

Last Updated: Aug 05 '11 at 10:07 PM