Home Unity

Few scripting questions

How to make waiting in unity js?
How to do actions for some other object, for excample I click start buttong, and camera goes left on x for 50.
How to hide objects.
Give me few excamples of simple js scripts for android touch inputs, like I touch game object and print "object is clicked", and script for sliding page down.
How to simply save files, like numbers and make them automicaly loaded next time android game is started, I want to same what answers were corect and some statistic things
I would rly like you give me script and description and try to avoid giving me links. Sorry for asking all this stuff, but I rly couldnt find answers, and link on unity for inputs was so confusing. Pls help.
And yes excample of js array script, like script [1], sript [2], and print then

Replies

  • SanderDL
    Options
    Offline / Send Message
    SanderDL polycounter lvl 7
    You are asking too many questions at once. Most of them are very basic too. I suggest you try to follow along these tutorials:

    http://walkerboystudio.com/html/unity_training___free__.html

    They are free and should cover most of your questions, one way or another. They have helped me a great deal in the past.
  • HammerFist3D2D
    Man they loke cool, but I am on mobile and cannot watch em. Any other suggestions/answers? Can u answer any. Guys I am sorry if I annoying but I dont have pc internet so cannot watch videos(except that I can dl some short utube videos)
  • SanderDL
    Options
    Offline / Send Message
    SanderDL polycounter lvl 7
    I'll try to answer some questions here. To get some more info you could also try opening the Unity scripting reference from inside Unity. If you do it this way, you don't need internet.


    - You can use: yield WaitForSeconds(3); this will wait 3 seconds before running the lines after it.

    - If you want to use a button to make something happen use OnGUI to place a button. Then use the update function to always make the camera go to a certain location, that you set in the GUI button.

    - you can hide things by turning off their renderer. Something like:

    Transform.render.setActive = false.

    - I save a really good video about touch input on mobile a while ago. I'll try to find it again and get back with some of the examples they show in there.

    - The most simple way to save things in Unity is Playerprefs.

    If you explain a bit more what you want to achieve exactly I might be adable to show some examples of how you could code it.
  • HammerFist3D2D
    Hey thank you man really a lot. About saving, i just want to save some strings and integers. Like what answer is already done and what was the answer.
    About touch input can you give me simple excample like: object is clicked, print message object is touched. With no possibiliti of more than one touch, i want this enter options os start or statistics. Also can u give me excample for scrolling page down, like not every lvl can get on one scren so u have to scroll down to see the rest
  • 2cat
    Options
    Offline / Send Message
    2cat polycounter lvl 5
    You can save strings, ints and floats using PlayerPrefs. PlayerPrefs.SetInt("intIDName", 1) .GetInt("intIDName"), SetString, GetString, GetFloat,SetFloat.

    Just browse the unity documentation on their website. All the information about touch events et cetera are in there. Just like PlayerPrefs, SetActive(), as is everything else you're asking for.

    Simple Google searches would've given you all these answers.
  • HammerFist3D2D
    Thx man. But I have to ask here because my internet is really really slow.
    Can u answes few next questions, I would be really thankful.
    If condition for OnMouseDown, like if clicked object is someObject do etc. And how to make this multi conditional, like if clicked object is someObject1 or clicked object is someObject2 etc do actions. Sorry for asking so basic questions but my browser is weak and I cannot go so much in browsing, and here u rly help me.
  • SanderDL
    Options
    Offline / Send Message
    SanderDL polycounter lvl 7
    you can give objects different tags. You can then check by it's tag like so:
    if (gameObject.tag == "sometag")
    {
         //do stuff
    }
    


    For the touch input you can do something like this:
    function Update()
    {
         var ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).phase == TouchPhase.Began);
         var hit : RaycastHit;
         if(Physics.Raycast(ray,hit))
       {
              if(hit.collider.tag == "Cube"
              {
                   Debug.Log("You've hit an object tagged cube");
              }
       }
    }
    

    This will cast a ray from the camera to the place that you've touched the screen. It will then look to see if what you've hit has a certain tag. If it does it logs a message in the console.

    I've haven't tested it, so I'm not sure it works exactly like that but it should point you in the right direction.
  • HammerFist3D2D
    SanderDL wrote: »
    you can give objects different tags. You can then check by it's tag like so:
    if (gameObject.tag == "sometag")
    {
         //do stuff
    }
    


    For the touch input you can do something like this:
    function Update()
    {
         var ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).phase == TouchPhase.Began);
         var hit : RaycastHit;
         if(Physics.Raycast(ray,hit))
       {
              if(hit.collider.tag == "Cube"
              {
                   Debug.Log("You've hit an object tagged cube");
              }
       }
    }
    

    This will cast a ray from the camera to the place that you've touched the screen. It will then look to see if what you've hit has a certain tag. If it does it logs a message in the console.

    I've haven't tested it, so I'm not sure it works exactly like that but it should point you in the right direction.

    Okay, I have never used raycast before, so it registers click over colision? because I use collision on models? I know I maybe sound like retard right now, but I guess I am for this.

    EDIT, also does it hits only first object, or and objects behind it. because I will have some objects behind.
    thx for answering
Sign In or Register to comment.