Forum rules - please read before posting.

Curser visible/invisible

Hi, 

I have a mini-game, that once the scene begins i want to make the cursor invisible' in the top two thirds of the screen and visible in the bottom third. My coding is poor so any ideas?

OR

the cursor is invisible for the entire scene but still 'there' if you get me?

Thanks!
«1

Comments

  • If you want to do a mini-game, you can't really get away from coding!  You'll have to write a script that changes the cursor's graphic according to the mouse position on-screen.

    Which cursor do you want to change?  The main cursor?  Somethine like this ought to do it:

    private Texture2D normalTexture;


    private void Start ()
    {
        normalTexture = AC.KickStarter.cursorManager.pointerIcon.texture;
    }


    private void Update ()
    {
        float mouseHeight = Input.mousePosition.y;
        float screenHeight = Screen.height;

        if (mousePosition.y / screenHeight) < 0.33f)
        {
            // Show cursor
            AC.KickStarter.cursorManager.pointerIcon.texture = normalTexture;
        }
        else
        {
            // Hide cursor
            AC.KickStarter.cursorManager.pointerIcon.texture = null;   
        }
    }


    Make a new C# script and replace that with the default Start/Update functions.
  • replace the script only on the scene i wish to change?

    the code is giving me a lot of errors
  • Replace
    if (mousePosition.y / screenHeight) < 0.33f)

    with
    if (mouseHeight / screenHeight < 0.33f)
  • thanks

    one more error

    Assets/TMOWM/Assets Shake/Scripts/CursorChange.cs(12,14): error CS0116: A namespace can only contain types and namespace declarations
  • plus, does the name of the script matter, and how exactly do i ensure it is just for a particular scene?
  • Place it on a gameobject in the scene you want it to affect.

    What line does the error refer to?  Be sure to place the code inside the class block.
  • This line:






    private Texture2D normalTexture;



    But the cursor is part of adventure gamer and is set in the managers?

    SO, I just create a game object and add script to it?

  • That's correct.

    Did you place the code inside your class correctly?  Repost the full contents of the script.
  • when i place the script in my folders that is the error i get and i cannot play without getting rid of errors.

    i am not sure how to place the script inside a class

    screenshot below with script

  • I was asking to see the script file itself - not the error messages.  The code I wrote for you goes inside the class.   As I explained in my previous post, you have to replace the Start and Update functions within a new script file with the code - not the entire file.

    If you need help with understanding how C# scripts work, Unity's own tutorials are a better place to start.
  • Hi, thanks, here is the script file. 


    I am still confused on how to go about replacing the update start ? and can keep getting the error when the script is just in the scripts folder without evening putting it in a gameobject in the scene?

    error:


    Thanks
  • edited March 2016
    As I explained before, the code needs to be placed in a class block.  This is not a forum for learning to code - Unity has plenty of tutorials for this.

    adventurecreator.org/files/NewCursor.cs
  • Got it, works, thanks!
  • I have just run into another problem with this, once out of the scene which has the cursor invisible in the middle of the scene, the cursor stays removed in other scenes after visiting it.

    What would I need to do to ensure normality with the script is reloaded after?

    thanks
  • You could try re-assigning the texture on an OnDestroy () function within the same script.
  • Hi Chris, I know this is not a scripting forum, but what would the line of code for this be that I add to the script you previously gave me?

    Thanks!
  • private void OnDestroy ()
    {
      // Show cursor
      AC.KickStarter.cursorManager.pointerIcon.texture = normalTexture;
    }
  • Thanks Chris

    Would I therefore have another script to make the cursor rotate like the one below?






    public class RotateCursor : MonoBehaviour {





        private Texture2D normalTexture;





        private void Start ()

        {

            normalTexture = AC.KickStarter.cursorManager.pointerIcon.texture;

        }





        private void Update ()

        {



            {

                //
     Rotate the object around its local X axis at 1 degree per second

                transform.Rotate (Vector3.right * Time.deltaTime);



                // ...also rotate around the World's Y axis

                transform.Rotate (Vector3.up * Time.deltaTime, Space.World);



            }

        }

    }  
  • The AC cursor is drawn with OnGUI calls, meaning it's not a GameObject and can't be rotated in the standard sense.  The script you've posted will just rotate the GameObject it's attached to.

    If you want to have the cursor rotate, you'll have to override the AC cursor with a GameObject sprite or some other in-scene graphic.

    The included World Space Cursor Example script can be attached to an object in your scene to take the place of your cursor - you could duplicate it and amend to suit your own needs.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.