- Home /
Unity shows me a picture of a screen whenever I mouse over the game screen.
Hi, I just recently made my first game and it was working fine with my device. But I wanted to add more so I came home and started working on it. For some reason whenever my mouse moves over the game screen it shows me the titlescene or at least the picture I use for the titlescreen. I published it to my phone and now wherever I touch it shows me the same image and now I can't even move or do anything else in my game. Any suggestions would really help.
Titlescreen = Splashscreen? $$anonymous$$y guess is, you did something wrong in you code. So it is difficult to tell you much of anything out of the blue.
Have you tried looking where that picture is referenced in your project. And check where that variable holding the image is all being used for. (Should obviously be in your OnGUIs)
the image is never referenced in the scripts. The image is a screen shot of my game. I took the screenshot, imported it into my assets, and pasted it on to a plane with an OnGUI script attached to it. The script has stayed the same but now even when the OnGUI isn't there it still shows up. Is there like a setting that I might have accidentally changed?
ok.. If you put that image on a plane (in a material), you don't need OnGUI() to display it. OnGUI is only for 2D. So I guess something must be doing something with that plane of yours. Have you checked where that is referenced in your scripts?
I only use OnGui to display the title and the buttons. And the plane is only referenced in that 1 OnGUI script. It's only started to act up now, but the OnGui was working fine earlier.
Add a splashscreen (Your Intro image) in Build settings->player settings->splash image. If you wish to make a separate Title screen you should include it as a New Scene and detect a Touch Event on it to begin a call of :
Application.LoadLevel ("First Level");
The reason it shows up when you touch anywhere is because mouse events and touch events are handled differently. If you do not use a proper Touch Handler a touch to the screen is the same as touching everything in view.
A touch handler looks something like the following and in this case it uses a raycast (shoots a line) from the screen touch position directly into the world and tests to see what the ray touches. Here, "StartGame" is the name of a 3DText object, but for you, you can set your image as a GUITexture for much the same effect. Note that my 3DText object has a Box Collider on it so I can detect the hit of the ray. GUITextures don't require a collider and live in the Camera space rather than the 3DWorld space.
function Update ()
{
if (Input.touchCount > 0)
{
// If there are touches...
var theTouch : Touch = Input.GetTouch (0);
// Cache Touch (0)
var ray = Camera.main.ScreenPointToRay(theTouch.position);
if(Physics.Raycast(ray,hit,500))
{
colName = hit.collider.gameObject.name;
if(Input.touchCount == 1)
{
if (theTouch.phase == TouchPhase.Began || theTouch.phase == TouchPhase.$$anonymous$$oved)
{
if(hit.collider.gameObject.name == "StartGame")
{
Application.LoadLevel ("TC1");
}
}
//if (theTouch.phase == TouchPhase.$$anonymous$$oved)
}
}
}
}
If this doesn't make sense, check out the Penelope iPhone tutorials and check out the Android build of the AngryBots tutorial. The Joystick prefab in the latter contains the Touch Handler and is worth a look.
Edit: OnGUI() is very expensive for most uses. $$anonymous$$ost people (and the stats/profiler) recommend you avoid it like the plague.
I understand what you are saying but my touch handler has been working really well. This problem has only started on my third version of my game, after I exported my project on a flash drive and started working on my home computer. It was working fine for versions one and two, and I'm pretty sure I've engaged some sort of setting, I just don't know what.
Did you export the project or copy the whole project folder? I work between my desktop and a netbook and I find that even though I'm using an exact copy of the whole project folder the different Unity installs will require separate setup and will seem to 'remember' different things. It's truly weird like that.
If you copy a folder back and forth, files you have deleted will still be present in the other copy and will essentially be copied back eventually. This can cause major problems if you have rewritten scripts. Check your project folder and see if you have multiply versions of the same files. Say you had a texture in your asset folder. If you modify this texture externally and drop it into the asset folder again, the old texture is not overwritten but renamed texture1. Look in your actual files and not in Unity, and you may find the cause of your problem.
Careful to add comments, not new answers.
Check in your actual asset files, not in Unity, for assets with numbers after them. Texture, Texture1 Compare them for differences.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Out of order Please help 1 Answer
How to use the Unity Remote on Android? 0 Answers
Question about ARcamera 0 Answers
Facebook SDK 6.2.2 for Unity doesn't work on my Android Device 0 Answers