Search Unity

Need a little help

Discussion in 'Scripting' started by Koker 007, Nov 17, 2013.

  1. Koker 007

    Koker 007

    Joined:
    Nov 17, 2013
    Posts:
    2
    Hello, I have a couple of silly questions about unity and C #. These problems I can not solve for quite some time
    1) I can not understand why the object is not assigned a tag "star1" in the script that I wrote. Object STARType-2: 1 is created but it is not assigned to tag star1.
    Code (csharp):
    1.  
    2.         else if (StarGenerateNumber<=3) {
    3.             for (Number=1;Number>2;Number++);
    4.             Star = GameObject.CreatePrimitive(PrimitiveType.Cube);
    5.             Star.name = "STARType-"+StarGenerateNumber+":"+Number;
    6.             if (Number<=1){
    7.                 Star.transform.position = new Vector3(0, 0, 0);
    8.                 Star.transform.localScale = Vector3.Scale(new Vector3(1, 1, 1), new Vector3(4096, 4096, 4096));
    9.                 //Голубая звезда
    10.                 StarCR = 127.0/2.55*0.01;
    11.                 StarCG = 255.0/2.55*0.01;
    12.                 StarCB = 212.0/2.55*0.01;
    13.                 Star.transform.renderer.material.color = new Color((float)StarCR,(float)StarCG,(float)StarCB);
    14.                 Star.tag = "Star1";
    15.             }
    16.             else if (Number<=2){
    17.                 Star = GameObject.CreatePrimitive(PrimitiveType.Cube);
    18.                 Star.name = "STARType-"+StarGenerateNumber+":"+Number;
    19.                 Star.transform.parent = GameObject.FindGameObjectWithTag("Star1").transform;
    20.                 Star.transform.localPosition = new Vector3(6144,0,0);
    21.                 Star.transform.localScale = Vector3.Scale(new Vector3(1, 1, 1), new Vector3(0.25f, 0.25f, 0.25f));
    22.                 StarCR = 127.0/2.55*0.01;
    23.                 StarCG = 255.0/2.55*0.01;
    24.                 StarCB = 212.0/2.55*0.01;
    25.                 Star.transform.renderer.material.color = new Color((float)StarCR,(float)StarCG,(float)StarCB);
    26.                 Star.tag = "Star2";
    27.                 //пробуем задать звезде star2 вращение относительно star1
    28.                 //Star.transform.localRotation =
    29.  
    2), which means "void" in C #? and how does it work?
    3) How to run a third-party script inside another script?

    I'm just starting to understand the C # language and at the same time mastering the unity.
    I apologize for such a rude question, but the answer to them I really need.
     
  2. rbx775

    rbx775

    Joined:
    Aug 16, 2010
    Posts:
    100
    I dont know C# to be honest, but I will give it a try since nobody answered yet...

    @1: line 2: Is there supposed to be a semicolon at the end ? + When you leave out the "swung brackets", only the next line is effected by the for loop.
    (If it works like Javascript at all.) I hope you considered that. :)

    @2: void is usually placed infront of a function to tell the compiler that the following function wont return any value of any kind.

    @3: I think in C# "public" declarations in combination with "classes" are prefered for such script interactions...


    Sry for my short and "unclear" answers. Actually I want to make another point:
    You should probably go through some more C# tutorials, some of that stuff is crucial,
    and you could miss out on very neat features of C#.
    Often, when you really want to archieve something but are struggling doing it,
    It demotivates you and your idea/concept will grow boring to you much faster.


    edit: And your questions are not rude at any point, no worries. :)
     
    Last edited: Nov 17, 2013
  3. Koker 007

    Koker 007

    Joined:
    Nov 17, 2013
    Posts:
    2
    Thanks for answers. The first question I myself have found the answer. Question 2 I'm still looking for an answer, and thank you. you helped me to solve it. sorry but the third question, I did not understand the fact that I do not know much English and I have problems with the translation. But thanks for the advice to use the books, I thought about it, and probably really should try the book.
    previously studied only through the Internet
     
  4. AustinK

    AustinK

    Joined:
    Dec 10, 2012
    Posts:
    86
    Your code looks like it should be wrapped in for braces within the for-loop?

    Also, I think you want the for-loops condition to be Number < 2, not Number > 2
     
  5. Glader

    Glader

    Joined:
    Aug 19, 2013
    Posts:
    408
    AustinK is right. You currently have a for loop that iterates over this block of code

    Code (csharp):
    1.  
    2. ;
    3.  
    Which is nothing. You need to enclose a for loop with brackets
    (Also, as AustinK has pointed out, Number>2 is always false. Think through the logic of your loop)

    Code (csharp):
    1.  
    2. for(int i = 0; i < 5; i++)
    3. {
    4.      Debug.log(i);
    5. }
    6.  
    "A tag can be used to identify a game object. Tags must be declared in the tag manager before using them." - Documentation

    Did you declare the tags in the tag manager?

    Void is basically an empty return type. I'm not far enough in comp sci. to tell you exactly what it is but for typical use you only need to know not to expect it to return any meaningful data such as an int value.
     
    Last edited: Dec 14, 2013
  6. Infinite_Gamer

    Infinite_Gamer

    Joined:
    Dec 6, 2013
    Posts:
    11
    In C# all "void" means is "function" in java script.
    for the 3rd question I would have to agree with rbx775 I think you would use "public"

    Here is a great you tube tutorial I think will really help you it sure helped me a lot.
    http://m.youtube.com/channel/UCR_3ge9-CEhA6USXMuthwDw


    Hoped this helped you
     
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    That's not what it means at all. What youv'e described is a syntax difference.

    If you were to define a JS function that returned a void in the same way as c#, it would look like this

    Code (csharp):
    1.  
    2. function DoStuff() : void
    3. {
    4.  
    5. }
    6.  
    A void is a type that's basically nothing... 'a void' if you will.. null could be considered a closer comparison.

    http://en.wikipedia.org/wiki/Void_type
     
unityunity