Search Unity

Please help the new guy

Discussion in 'Scripting' started by eliphas, Jun 10, 2006.

  1. eliphas

    eliphas

    Joined:
    Mar 31, 2006
    Posts:
    9
    Hi everyone, I realise these may be very simple questions for most of you but I can't work out how to do them.
    By the way, I'm completely new to unity and game programming so please excuse my ignorance.

    I have recently started to work on my first game, and even though I haven't done anything like this before I got most of it up and running in one night, but there are two things puzzling me.

    1)I have an object I want to use as a cannon that will shoot spheres. This cannon can only rotate around the y axis. Obviously I want the sphere to be emitted in whatever direction the cannon is pointing when the player presses fire.
    I'm not asking for scripts or complete answers, but if someone could point me in the right direction such as which classes to use or the general theory behind how this is normally done, I would be grateful.

    2) How do I read the current state of an object? I want to right a script for one object that depends on the current y position of another object. How do I get the y value of this other object into my script?

    Also I'm using javascript in case that matters.

    Thanks for your help, and thanks to the guys who coded the unity engine, I never thought I'd stand a chance at making my own game-It's good to be proven wrong!
     
  2. Mike08

    Mike08

    Joined:
    Dec 29, 2005
    Posts:
    124
    Hi eliphas

    To question 1: Use the command 'Instantiate' (You will find an example in the documentation) and create a empty gameObject and add it to the front of the canon (where the sphere should come out) and use this as position in the Instantiate command.

    To question 2:

    Code (csharp):
    1. var Object : Transform;
    2.  
    3. function Update ()
    4. {
    5.    var position = Object.position.y //now you can use the position of Object
    6. }
    You can atatch any Object to the script in the Inspector.

    I hope this will help you to answer your questions.

    Have a lot of fun with Unity

    By
     
  3. eliphas

    eliphas

    Joined:
    Mar 31, 2006
    Posts:
    9
    Wow, that was quick!
    Thanks for your help Mike3D.
    Hopefully, when I get this project finished I'll post it for you guys to see.
    Anyway, back to work!

    Cheers, Eliphas.