Unity Community


Page 42 of 66 FirstFirst ... 32404142434452 ... LastLast
Results 821 to 840 of 1315

  1. Posts
    47
    What I wanted to get access to is a variable, not an object.

    As I said, I managed to do it by declaring it as static, but I guess it can be done otherwise.


  2. Posts
    16
    I can see that.

    What I meant was that you could have an empty game object and attach a script to it which holds any variables you want to keep between scenes. (and I dont think I explained that very well)

    I guess it comes down to personal preference in the which one to use, as they both seem to do the job.


  3. Posts
    47
    Then, those vars would have to be static too...

    I mean, let's say that empty object has a score var, in emptyObjectScript. Such var is going to be updated (according to lab01) in enemyScript... so I would have to get it from enemyScript, and the variable from emptyObjectScript would be no more than a simple reference to this one.

    I don't know if you know what I mean.


  4. Posts
    16
    I see what you're saying.

    Like I said, I've not really researched it at all, so you're probably correct in your approach to the problem.


  5. Location
    Elk Grove
    Posts
    1
    thank you!, Thank you!, THANK YOU!


  6. Location
    Madrid
    Posts
    3
    Are you guys on youtube?


  7. Posts
    47
    function OnTriggerEnter(other : Collider){
    if(other.gameObject.tag == "Player"){
    other.GetComponent("scriptPlayer").life -= 1;
    }
    }
    This is it. It's done in the 2nd lab.
    In case someone else needs it, I'm posting it.

    This way, you can access to a variable set in another .js and change its value.
    In this case, it's the var life, which is set in scriptPlayer.js.



    EDIT:
    Okay, my bad....this code is supposed to say what I meant, but I've been already struggling for 30min or so... and can't get it working.

    This is the error that I'm getting.
    Assets/scriptAstroid.js(31,52): BCE0019: 'lives' is not a member of 'UnityEngine.Component'.
    The GetComponent function is called correctly, so I don't know what I'm doing wrong, as my code is exactly the same as the video's.

    Just for clarification: I changed the "life" var to "lives", in case somebody is wondering if that's the problem.



    EDIT2:

    And again I'm editing.
    As looking for info, I've stumbled upon this.
    GetComponent ("Item") returns a Component

    GetComponent (Item) returns an Item
    I've also something about "#pragma strict", which I don't really know what it is yet.
    But I guess it's something like strict HTML, which doesn't allow you to make some "tricks" and everything has to be severely regulated.

    So.. in the end, I have two solutions to my problem:
    1)
    Commenting the #pragma strict line and keeping the quotation marks as in here:
    Code:  
    1. other.GetComponent("scriptPlayer").lives -= 1;

    or 2)
    leaving #pragma strict uncommented (which would be the wise option) and set the following line as this:
    Code:  
    1. other.GetComponent(scriptPlayer).lives -= 1;

    Either way, it works now
    Last edited by Miyavi; 03-14-2012 at 04:24 PM.


  8. Posts
    47
    Oh well, here I am with another problem... I don't know why this is happening, as there should be no problem with it.

    This is my code, from scriptShield:
    Code:  
    1. #pragma strict
    2. //Shield Script
    3.  
    4. //Inspector variables
    5. var shieldStrength : int = 3;
    6.  
    7. //Private variables
    8.  
    9. function Start(){
    10.     shieldStrength = 3;
    11. }
    12.  
    13. function Update(){
    14. print("shield   : " + shieldStrength);
    15.     if (shieldStrength <= 0){
    16.         Destroy(gameObject);
    17.     }
    18. }
    19.  
    20. function OnTriggerEnter(other : Collider){
    21.     if(other.tag == "Astroid"){
    22.         shieldStrength -= 1;   
    23.     }
    24. }

    When I turn on my shield, it prints out "3", but whenever I hit an object, it doens't ever come down.
    Tags are well assigned.

    EDIT:
    I've changed the code into scriptAstroid.js so that when it collides with the shield, shieldStrength decrements.

    It seems to work... I just don't know why it doesn't work the first way I did it.
    Last edited by Miyavi; 03-15-2012 at 05:34 AM.


  9. Posts
    20
    Quote Originally Posted by dayunbao View Post
    OK, I found a work around, but it still doesn't work perfectly.

    I've "finished" the lab, but there is a problem with either the ChangePlayerState function in the colliderAttackBox script, or the SetPlayerState function in the playerProperties script. I've triple or maybe even quadruple checked the code, and I don't see any problems with it, but when Mario hits a gumba, there's some confusion with the states. It seems that the MarioDead case is being called every time, even when Mario is big and should just change to small and not die. I've spent a lot of time playing around with the code trying to come up with a solution, but haven't had any luck. Anyone else having problems with this?

    I'd like to make a suggestion to the Walker brothers, and that is please include the completed scripts with the downloadable assets. There are a few very annoying things that happen when you don't include them. For example, every time I want to check my code I need 1) an internet connection, 2) to let the videos load (which can take a long time depending on the length of the video and speed of the connection), and 3) scanning the video for the right part that shows the code I want to check. I've spent A LOT of time doing the above to try and find what is wrong with my code, and so far I can't find anything. Also, unlike the other labs, you do not actually have a video that only shows the code. So, I've spent a few hours every day for about three weeks working through the 2D Mario tutorial, and now I'm "finished" and don't even have a playable game because of problems with the code that I can't identify, and I don't have anything to check it against...it's a bit frustrating.
    This would definitely be a 'nice to have' i think as well. Personally, it's to save those hours looking over letter by letter to find your typo, when really it's a matter of doing a 'diff' to find your error. Not to say, that I'm not actually typing line by line while following along with the boys videos. I've run into code issues oh about 3 or 4 times now for the 2d mario game, all of which I've been able to find my type or the fix on the forum (that enum intParse issue around video 56 or so).

    but that's just my two cents. The walkerboys are 5 stars in my books in any case.


  10. Posts
    47
    Well, so finally, my second lab is almost done.
    I'm actually working on some added features, which I hope to implement soon.

    Please, play it, and tell me your opinion about it

    http://miyavi.net76.net/labs/lab02/W...WebPlayer.html

    PS: Yellow capsules enhance Double Shot.


  11. Posts
    3
    Hey there! Nice tutorial but I'm having problems with Mac OS X Standalone Unity.

    Unity App 9 (10-13) Animation Event key

    Here's Your own script called "Cube" in my project
    Code:  
    1. #pragma strict
    2.  
    3. function PrintEvent (num : int)
    4. {
    5. Debug.Log("Hello Event"+num);
    6. }
    7.  
    8. function PlayAudio (aud: AudioClip)
    9. {
    10. audio.clip=aud;
    11. }
    12.  
    13. function PlayParticle (par: GameObject)
    14. {
    15. Instantiate( par , transform.position , transform.rotation );
    16. }
    17.  
    18. function ChangeMaterial ()
    19. {
    20. renderer.material.color=Color.red;
    21. }

    I have a Cube object in the scene with a Cube script

    I can make animation frames, the object moves when I press the Play animation button.

    But whenever I make animation events I get nothing

    After following the tutorial and setting up the events my cube:
    a) does not change color
    b) does not display the particle effect
    c) does not play the sound (even tho it has the sound selected in the key and sound component turned on)
    d) does not print anything to the console

    Is there anything that I'm doing wrong ? Were there any major changes from unity 3 to unity 3.5 that make those tutorial animation events not work at all ? Any workarounds ?


    Edit: Got it working properly in all projects, it started working when I did some javascript tutorials, maybe there are some project settings in unity changed there ? Anyways disregard the post and if You run into this problem just go ahead with the lessons and everything will start working sooner or later.
    Last edited by Sarnum; 03-19-2012 at 12:49 AM.


  12. Posts
    14
    Quote Originally Posted by pn99 View Post
    This would definitely be a 'nice to have' i think as well. Personally, it's to save those hours looking over letter by letter to find your typo, when really it's a matter of doing a 'diff' to find your error. Not to say, that I'm not actually typing line by line while following along with the boys videos. I've run into code issues oh about 3 or 4 times now for the 2d mario game, all of which I've been able to find my type or the fix on the forum (that enum intParse issue around video 56 or so).

    but that's just my two cents. The walkerboys are 5 stars in my books in any case.
    Yeah, they're great. I love these tuts, and I've learned so much from them. My only point is that since it would only take about 5 seconds to include the scripts, why not do it? Every other instructional programming book or video does it.

    I'm not ruling out a typo, but I always go over my code with a fine tooth comb if there's any problem. I wouldn't post a question without first checking. I've had numerous problems related to typos while doing these tuts, but I found and fixed those myself without asking on the forum. Anyway, like I said having the finished code saved on hard drive to check against would make checking for errors 100 times easier.


  13. Posts
    14
    Quote Originally Posted by ianismrt View Post
    I had that exact same problem, after searching around I found this bit of code:
    if(other.tag == "pathNode")
    {
    var linkToPathnode = other.GetComponent(pathNode); //get pathNode.js
    gumbaState = parseInt(linkToPathnode.pathInstruction);
    }

    "The parseInt() function parses a string and returns an integer" which just means it takes your enum text, and reads it numerically... Which I think it was supposed to do anyway... why it only sometimes works is beyond me.

    This problem drove me NUTS, but it was a simple fix.
    Great, thanks so much. I'll try it out soon!


  14. Location
    Louisville, Ky
    Posts
    122
    Quote Originally Posted by pn99 View Post
    This would definitely be a 'nice to have' i think as well. Personally, it's to save those hours looking over letter by letter to find your typo, when really it's a matter of doing a 'diff' to find your error. Not to say, that I'm not actually typing line by line while following along with the boys videos. I've run into code issues oh about 3 or 4 times now for the 2d mario game, all of which I've been able to find my type or the fix on the forum (that enum intParse issue around video 56 or so).

    but that's just my two cents. The walkerboys are 5 stars in my books in any case.
    I think they are setup perfectly for a good learning experience. I learned a lot from these and the couple times I messed up a script with a typo or was totally confused on what they was talking about I went to searching the internet for a little more information.

    I think providing the scripts would not teach very well. People would just download the scripts and try get them working without learning anything. The scripts would not make for the best learning experience in my opinion. And of course this is my 2 cents since most of what I learned came from these tutorials.

    Walker Boys did a great job and put a lot of time into these tutorials and videos all a person has to do is actually put in their time to learn them properly. Not only go through them but actually use everything they teach. Not supplying the scripts makes it where the ones that want to learn this will and not just watch the video and add a script to an object.


  15. Posts
    3
    Hey guys, I'm doing the first project now and I'm wondering how to destroy a particle effect using shuriken. There's definitely no destroy switch there and calling the destroy function just calls up a general unity error.

    I'm trying something like this
    So, I know that my explosion is not alive anymore and I'd like to destroy it:
    Code:  
    1. if(explosion && explosion.particleSystem.IsAlive() == false)
    2. {
    3.     //I'd really like to have a way of destroying the explosion
    4. }

    when trying to just destroy the object 10 seconds after spawning the explosion I get
    Code:  
    1. Instantiate(explosion,transform.position,transform.rotation);
    2. Destroy (explosion, 10);
    "Destroying assets is not permitted to avoid data loss"
    Last edited by Sarnum; 03-21-2012 at 04:03 AM.


  16. Location
    Louisville, Ky
    Posts
    122
    @Sarnum I could be wrong but I think might work is attach it to a empty game object then make it a prefab and then use the prefab since you can destroy the prefabed object.


  17. Posts
    3
    @tra2002

    Well the explosion particle effect is already a prefab sitting in my "Project" window,
    I only attach it to my scriptActorEnemy script via the variable "explosion". As shown here :
    too bad Unity Devs did not add the Autodestruct to Shuriken, huh ? ;/

    Okie dokie, someone figured it out for me, for that gratitude ;p

    Here's the link to my unity question on unity answers
    Last edited by Sarnum; 03-21-2012 at 07:25 AM.


  18. Posts
    13
    Could anyone give me a tip for one of the assignments in Lab 1, its listed below:

    "Counter - 3 second countdown for the Sphere before disappearing"

    Do I need to create a new enemy script to give the Sphere a 3second timer before disappearing


  19. Posts
    14
    I think providing the scripts would not teach very well. People would just download the scripts and try get them working without learning anything.
    Like I said before, it's common practice to include the completed code, and anyone with a modicum of maturity and who is actually interested in learning scripting will not just copy and paste the code. Putting everything in the videos does't guarantee that no one will "cheat." I could just skip to the end of a video, pause it, type out all the code without listening to the explanation and not learn anything. Including the completed code is for debugging purposes.

  20. Thank you so so so much!

    These are gold. I am new to Unity. I went through a few of the UI videos, and now going through Mario 2D clone. So far I can tell you, they are absolutely amazing. I didn't have any problem following you in JavaScript, even though I have never used it before. I'm planing, when I'm done with the tut, to repeat it myself in C#, just to test my knowledge.

    Again thank you for sharing your knowledge. I really don't know how to express my gratitude, but you are awesome!
    These are extremely well put together. Your voice sounds pleasant too

    Great job!

Page 42 of 66 FirstFirst ... 32404142434452 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •