Search Unity

Space Shooter Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 26, 2015.

  1. Tradge20

    Tradge20

    Joined:
    Feb 9, 2018
    Posts:
    4
    can I do this tutorial without switching to webGL? I have 32 bit windows and I can't use WebGL.
     
  2. Tradge20

    Tradge20

    Joined:
    Feb 9, 2018
    Posts:
    4
    I can't use WebGL being I'm on windows with 32 bit. can I use this tutorial with another build?
     
  3. Artermis

    Artermis

    Joined:
    Feb 11, 2018
    Posts:
    5
    I am on the tutorial shooting shots. I have done everything in the tutorial, set everything the way the guy says it too. I get one perfect bolt and then the rest fire in a laser like way with pretty much no space between them. I have rechecked my code and I even changed the timing for the firing seeing if I could fix it in the game instead of the code but the same thing is happening. Please help. Never mind. I found the issue. I had an extra semicolon somewhere it wasn't supposed to be
     
    Last edited: Feb 13, 2018
  4. Bragou

    Bragou

    Joined:
    Feb 13, 2018
    Posts:
    1
    Hi there !
    I'm on the "Game Controller" part, and I wonder why we use "Quaternion.identity".
    My game is working the same way if I write :

    Quaternion spwanrotation = new Quaternion();
    or
    Quaternion spawnRotation = Quaternion.identity;

    Oh and an other question : Why do we have to first declare a variable at the root of our script then initialize it in the start function ? Why can't we just declaring AND initializing in the same sentence ? In other words why do we do that :

    private int score;
    void Start ()
    {
    score = 10;
    }

    rather than that :

    private int score = 10;
     
    Last edited: Feb 13, 2018
  5. E2max007

    E2max007

    Joined:
    Jan 18, 2018
    Posts:
    3
    @Tradge20 I doing this tutorial at the moment and I guess you can do it for any platform you want. I think you can do it for windows standalone.

    @Bragou To answer you second question:
    Meet Score the variable. His job is to remember something. First we call him to the scene: Score get you ass over here. After a while we say: score remember this: 10! When we have scored more points we increase it: now remember 1000.

    I am not sure how Unity handles the placement of variable in a script and depending in what class they are. I think its possible to declare score with a value of 10. But then at the moment its declared the score will already be 10.
    And if you would declare the score every time the scores increases the score doesn't increases but just gets changed out by another score "guy".

    Does this help?
     
  6. LelandGreen

    LelandGreen

    Joined:
    Oct 6, 2017
    Posts:
    13
    On your first question, the only reason to use the Quaternion() constructor is to provide one of the X, Y, or Z values. If you provide none, I believe the result is the same as Quaternion.Identity – i.e., Quaternion.Identity simply returns a Quaternion created with the default constructor.

    On your second question, you're basically asking why C# syntax is that way. Perhaps you need to solidify your C# skills? (Or merely accept this answer, if that's all you need.) More specifically, a static variable is much different than a member variable (field)!
     
  7. LelandGreen

    LelandGreen

    Joined:
    Oct 6, 2017
    Posts:
    13
    WebGL is definitely cross-platform and I know it's available on Windows 32 bit. So I have no idea why you can't use it in Windows 32 bit.

    I guess it's just that Unity doesn't support that??? Anyone?
     
  8. aldab

    aldab

    Joined:
    Feb 18, 2018
    Posts:
    1
    Hi
    I wanted to know why doesn't this code Destroys the shot :
    Code (CSharp):
    1.  if (shot.transform.position.z >= boundary.zMax )
    2.             Destroy(shot);
    3.          
    4.  
    I Understand the code written in the tutorial, but I wanted to try another way
    Thank You!
     
    Last edited: Feb 18, 2018
  9. mikemcbrien

    mikemcbrien

    Joined:
    Feb 18, 2018
    Posts:
    1
    Hey I'm also new to Unity. I found that I had added a slight tilt to my ship when moving forwards or backwards. This caused the bolts fired to move in the Y direction (not noticeable to the game camera), and exit the boundary and be removed before leaving the screen.
     
  10. Ferrim

    Ferrim

    Joined:
    Feb 18, 2018
    Posts:
    2
    Please help.
    What's wrong with these bolts?

    It looks like they are stretched from the z-axis to the x-axis.
    Although if you put the camera on top then everything is ok.
     

    Attached Files:

    Last edited: Feb 18, 2018
  11. garethsparks

    garethsparks

    Joined:
    Feb 20, 2018
    Posts:
    1
    I just finished part 7 and my shots are rotating on the X axis along with the normal ship tilt applied in the tutorial. I am sure I can figure out how I'd fix this, but I want to know if I missed a step in the tutorial (best practices and all) or if this is something the creator didn't account for.

    EDIT: from looking at the done copy, it doesn't seem fixed? Shot is being instantiated with shotSpawn.rotation. It should be some version of shotSpawn.rotation with the X rotation zeroed out, right? I haven't tested the "done" project yet (not sure how yet) to see if it's visible. I just want to be sure there isn't some other setting I'm missing.
     
    Last edited: Feb 20, 2018
  12. Ferrim

    Ferrim

    Joined:
    Feb 18, 2018
    Posts:
    2
    This is not rotation. May be camera views?
    Because from topview camera it looks fine.
     
  13. crkobel

    crkobel

    Joined:
    Feb 22, 2018
    Posts:
    1
    In the first section to set up your project when you select your "build target", web player is not one of the listed options. The ones that are available are the default (PC, mac and linux standalone), iOS, universal windows platform, webGL, tvOS, android, xbox one, PS vista, ps4 and facebook. Which one should I select? or do I just leave it as the default?
     
    Veldishpar likes this.
  14. Alexgwenn

    Alexgwenn

    Joined:
    Feb 11, 2018
    Posts:
    1
    Is there sample code to respawn the player a number of times before the game is over?

    Im guessing the player would have to be converted to a prefab and the GameController script and DestroyByContact script would need to be altered.
     
  15. totemh

    totemh

    Joined:
    Jan 30, 2018
    Posts:
    1
    Try adding a "GUI Layer" component to the Main Camera Game object.
     
  16. Teleprototype

    Teleprototype

    Joined:
    Feb 24, 2018
    Posts:
    1
    Hi there! I just started using Unity professional and am also learning C# on the fly as I do these tutorials. During "moving the player" video, we write and attempt to compile the step by step script in the video. I am having an issue with rigidbody.velocity, position.x, position.z, and rotation parts of the script.

    " 'UnityEngine.Component' does not contain a definition for 'velocity' and no extension method 'velocity' accepting a first argument of type 'UnityEngine.Component' could be found. Are you missing a using directive or an assembly reference?"

    The second issue is using:

    Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), Mathf.Clamp (rigidbody.positionz, boundary.zMin, boundary.zMax);

    The error message is the same as above except replace "velocity" with "position".

    Last issue:

    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);

    Again, same error message but replace "rotation" with "velocity"

    ***I am using Unity 5.1 and monodevelop as the script editor***


    Again I'm very new to this so pardon me.

    Thanks
     
  17. V_nav

    V_nav

    Joined:
    Feb 25, 2018
    Posts:
    2
    While the player shoots the lazer,when the game object instantiates it stays there for a time and then starts to move in forward direction
     
  18. V_nav

    V_nav

    Joined:
    Feb 25, 2018
    Posts:
    2
    its due to old version style.They have changed the syntax a bit now. To make it work declare a variable of type Rigidbody named rigidbody. then write as
    private Rigidbody rigidbody ;
    void Start ()
    {
    rigidbody= GetComponent<Rigidbody>();
    }
    then try to compile again it works
     
  19. Northsight

    Northsight

    Joined:
    Feb 12, 2018
    Posts:
    2
    Hi,

    i am struggling a little by understanding the handshake between the scripts variables´.

    In the Destroy script we are using the variable "scoreValue" to add it to the gamecontroller script by this line:

    gameController.AddScore (scoreValue);

    and then insider the gamecontroller we are using for counting:

    public void AddScore (int newScoreValue)
    {
    score += newScoreValue;
    UpdateScore (); }

    my question is why do these variables have different names? and how could they have the same content? is the "new" any kind of instruction?
     
  20. NevinOliver

    NevinOliver

    Joined:
    Feb 10, 2018
    Posts:
    1
    Hey I'm stuck. The tutorial calls for me to enter the build settings and change the build to "Web Player" There are no such settings in unity that reflect what the tutorial teacher is using. Does this matter?
     
  21. rctacbad

    rctacbad

    Joined:
    Jan 29, 2018
    Posts:
    1
    I have a question regarding part 1.5 Moving the player. After applying the clamp with boundaries xMax=6, I noticed that while pressing the right arrow key, the player transform x position can reach 6.2, and upon releasing the right arrow key, the x position goes to 6.0. This is when speed=10. Why does clamping behave this way? I was expecting the x position to be never exceed a value of 6.0 since this is xMax.
     
  22. madelineleclair

    madelineleclair

    Joined:
    Feb 25, 2018
    Posts:
    5
    Afternoon,

    I'm having an issue with my asteroids moving in a circular motion as they fall from the top to the bottom of the screen. They never fall in a straight line like in the tutorial. If anyone can help point me to the cause or in the right direction, I would greatly appreciate it.

    Here is my code for the rotation:
    Code (CSharp):
    1. public class random_rotator : MonoBehaviour {
    2.  
    3.     public float tumble;
    4.     private Rigidbody rb;
    5.  
    6.     void Start () {
    7.         rb = GetComponent<Rigidbody>();
    8.         rb.angularVelocity = Random.insideUnitSphere * tumble;
    9.     }
    10. }
    and for the mover:

    Code (CSharp):
    1. public class Mover : MonoBehaviour {
    2.     private Rigidbody rb;
    3.     public float speed;
    4.     // Use this for initialization
    5.     void Start () {
    6.         rb = GetComponent<Rigidbody>();
    7.         rb.velocity = transform.forward * speed;
    8.     }
    9. }
     
  23. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    That doesn't matter. You can build for whatever, or simply run it in the editor, as I'm sure you've found out. :)
     
  24. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    The physics internal loop happens just after FixedUpdate, so the velocity is processed, and the next fixed update will try to clamp it.. however, if you're still pressing the key, there is more speed..
     
  25. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I think that is a bug (by the presenter), because that may only be working by accident (script execution order).
    I could be wrong, however .. a fix for your issue would be to use the world direction. I'm not familiar with the game completely, but try Vector3.down instead of transform.forward (or whichever world axis/direction the asteroid is supposed to fall/travel).
     
  26. Deleted User

    Deleted User

    Guest

    Tutorial #5
    Assets/Scripts/PlayerController.cs(37,64): error CS0103: The name `tilt' does not exist in the current context
    Help
     
  27. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You'd have to post your script. Maybe it's mispelled or you declared it in the wrong section.
     
    Deleted User likes this.
  28. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. [System.Serializable]
    6. public class Boundary{
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9. public class PlayerController : MonoBehaviour {
    10.     public float speed;
    11.     public Boundary boundary;
    12.     private Rigidbody rb;
    13.     private void Start (){
    14.         rb = GetComponent<Rigidbody>();
    15.     }
    16.     private void FixedUpdate(){
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    20.         rb.velocity = movement * speed;
    21.         rb.position = new Vector3 (
    22.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    23.             0.0f,
    24.             Mathf.Clamp(rb.position.z , boundary.zMin, boundary.zMax)
    25.         );
    26.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    27.     }
    28. }
    29.  
     
    Last edited by a moderator: Mar 4, 2018
  29. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You forgot to declare the float variable tilt (under speed, and above 'boundary' in the tutorial)... where it's placed exactly isn't important, I just mentioned that so you can look there to see.

    Also, when you're multiplying by the 'tilt', you can use 'rb' instead of getting the component for the rigidbody. :)
     
    Deleted User likes this.
  30. Deleted User

    Deleted User

    Guest

    Life saver.... Thank you so much
     
  31. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You're welcome.
     
    Deleted User likes this.
  32. Deleted User

    Deleted User

    Guest

    New Issue

    Assets/Scripts/GameController.cs(32,9): warning CS0162: Unreachable code detected
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class GameController : MonoBehaviour {
    6.     public GameObject hazard;
    7.     public Vector3 spawnValues;
    8.     public int hazardCount;
    9.     public float spawnWait;
    10.     public float startWait;
    11.     public float waveWait;
    12.     private void Start()
    13.     {
    14.         StartCoroutine(SpawnWaves());
    15.     }
    16.     private IEnumerator SpawnWaves()
    17.     {
    18.         yield return new WaitForSeconds(startWait);
    19.         while (true) {
    20.             for (int i = 0; i < hazardCount; i++) {
    21.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    22.                 Quaternion spawnRotation = Quaternion.identity;
    23.                 Instantiate(hazard, spawnPosition, spawnRotation);
    24.                 yield return new WaitForSeconds(spawnWait);
    25.             }
    26.         }
    27.         yield return new WaitForSeconds(waveWait);
    28.     }
    29. }
    30.  
    Didn't Think It Would Do Anything But It Seems To Be Preventing Me From Ending The Creation Of Asteroids After The Player Crashes
     
    Last edited by a moderator: Mar 4, 2018
  33. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class GameController : MonoBehaviour {
    6.     public GameObject hazard;
    7.     public Vector3 spawnValues;
    8.     public int hazardCount;
    9.     public float spawnWait;
    10.     public float startWait;
    11.     public float waveWait;
    12.     private void Start()
    13.     {
    14.         StartCoroutine(SpawnWaves());
    15.     }
    16.     private IEnumerator SpawnWaves()
    17.     {
    18.         yield return new WaitForSeconds(startWait);
    19.         while (true) {
    20.             for (int i = 0; i < hazardCount; i++) {
    21.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    22.                 Quaternion spawnRotation = Quaternion.identity;
    23.                 Instantiate(hazard, spawnPosition, spawnRotation);
    24.                 yield return new WaitForSeconds(spawnWait);
    25.             }
    26.             yield return new WaitForSeconds(waveWait);
    27.         }
    28.     }
    29. }
    30.  
    fixed it haha didn't realize my WaitForSeconds(waveWait); function was outside my loop haha
     
    Last edited by a moderator: Mar 4, 2018
  34. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Deleted User likes this.
  35. Deleted User

    Deleted User

    Guest

    Found A New Obsolete Reference Assets/Scripts/GameController.cs(40,29): warning CS0618: `UnityEngine.Application.LoadLevel(int)' is obsolete: `Use SceneManager.LoadScene' Any idea how I go about changing the reference I'm so confused

    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.SceneManagement;
    7. public class GameController : MonoBehaviour {
    8.     public GameObject[] hazards;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.     public GUIText scoreText;
    15.     public GUIText restartText;
    16.     public GUIText gameOverText;
    17.     private bool gameOver;
    18.     private bool restart;
    19.     private int score;
    20.     private void Start()
    21.     {
    22.         gameOver = false;
    23.         restart = false;
    24.         restartText.text = "";
    25.         gameOverText.text = "";
    26.         score = 0;
    27.         UpdateScore();
    28.         StartCoroutine(SpawnWaves());
    29.     }
    30.     private void Update()
    31.     {
    32.         if (restart) {
    33.             if (Input.GetKeyDown(KeyCode.R)) {
    34.                 //SceneManager.LoadScene("Main");
    35.                 Application.LoadLevel(Application.loadedLevel);
    36.             }
    37.         }
    38.     }
    39.     private IEnumerator SpawnWaves()
    40.     {
    41.         yield return new WaitForSeconds(startWait);
    42.         while (true) {
    43.             for (int i = 0; i < hazardCount; i++) {
    44.                 GameObject hazard = hazards[Random.Range(0, hazards.Length)];
    45.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    46.                 Quaternion spawnRotation = Quaternion.identity;
    47.                 Instantiate(hazard, spawnPosition, spawnRotation);
    48.                 yield return new WaitForSeconds(spawnWait);
    49.             }
    50.             yield return new WaitForSeconds(waveWait);
    51.             if (gameOver) {
    52.                 restartText.text = "Press 'R' For Restart";
    53.                 restart = true;
    54.                 break;
    55.             }
    56.         }
    57.     }
    58.     public void AddScore(int newScoreValue) {
    59.         score += newScoreValue;
    60.         UpdateScore();
    61.     }
    62.     private void UpdateScore() {
    63.         scoreText.text = "Score: " + score;
    64.     }
    65.     public void GameOver() {
    66.         gameOverText.text = "Game Over!";
    67.         gameOver = true;
    68.     }
    69. }
    70.  
    71.  
    72.  
    73.  
    74.  
    75.  
     
    Last edited by a moderator: Mar 4, 2018
  36. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Deleted User likes this.
  37. Deleted User

    Deleted User

    Guest

    Here Is My New Code Works Well For WebGL:
    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.SceneManagement;
    7. public class GameController : MonoBehaviour {
    8.     public GameObject[] hazards;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.     public GUIText scoreText;
    15.     public GUIText restartText;
    16.     public GUIText gameOverText;
    17.     private bool gameOver;
    18.     private bool restart;
    19.     private int score;
    20.     private void Start()
    21.     {
    22.         gameOver = false;
    23.         restart = false;
    24.         restartText.text = "";
    25.         gameOverText.text = "";
    26.         score = 0;
    27.         UpdateScore();
    28.         StartCoroutine(SpawnWaves());
    29.     }
    30.     private void Update()
    31.     {
    32.         if (restart) {
    33.             if (Input.GetKeyDown(KeyCode.R)) {
    34.                 SceneManager.LoadScene("Main");
    35.                
    36.             }
    37.         }
    38.     }
    39.     private IEnumerator SpawnWaves()
    40.     {
    41.         yield return new WaitForSeconds(startWait);
    42.         while (true) {
    43.             for (int i = 0; i < hazardCount; i++) {
    44.                 GameObject hazard = hazards[Random.Range(0, hazards.Length)];
    45.                 /*
    46.                    
    47.                     // Making Enemy Appear Behind Player
    48.                     bool flag = (Random.value < 0.5f);
    49.                     if(){
    50.                    
    51.                         Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    52.                         spawnValues.z = (16 or -16)
    53.                    
    54.                     }
    55.                      
    56.                      
    57.                 */
    58.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    59.                 Quaternion spawnRotation = Quaternion.identity;
    60.                 Instantiate(hazard, spawnPosition, spawnRotation);
    61.                 /*
    62.                  
    63.                     // Making Enemy Appear Behind Player
    64.                     GameObject clone = Instantiate(hazard, spawnPosition, spawnRotation);
    65.                     ReverseDirection(clone);                                    
    66.                  */
    67.                 yield return new WaitForSeconds(spawnWait);
    68.             }
    69.             yield return new WaitForSeconds(waveWait);
    70.             if (gameOver) {
    71.                 restartText.text = "Press 'R' For Restart";
    72.                 restart = true;
    73.                 break;
    74.             }
    75.         }
    76.     }
    77.     /*
    78.      
    79.         // Making Enemy Appear Behind Player
    80.         private void ReverseDirection(GameObject clone){
    81.        
    82.             clone.transform.rotation.y = 0;
    83.             clone.GetComponent<mover>().speed = 5;
    84.         }
    85.     */
    86.     public void AddScore(int newScoreValue) {
    87.         score += newScoreValue;
    88.         UpdateScore();
    89.     }
    90.     private void UpdateScore() {
    91.         scoreText.text = "Score: " + score;
    92.     }
    93.     public void GameOver() {
    94.         gameOverText.text = "Game Over!";
    95.         gameOver = true;
    96.     }
    97. }
    98.  
    99.  
    100.  

    Also Anyone Know What The New GUI Text Is Going To Be Because I Also Get This Error:

    Assets/Scripts/GameController.cs(14,12): warning CS0618: `UnityEngine.GUIText' is obsolete: `This component is part of the legacy UI system and will be removed in a future release.'
     
  38. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Been "replaced" for some time by the UI game objects: Create -> UI -> Text for example.
     
    Deleted User likes this.
  39. Deleted User

    Deleted User

    Guest

    How Do I Set That Up? Are There Any Videos Or Forums On This?
     
  40. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  41. Deleted User

    Deleted User

    Guest

    Final chapter and of course I get an error that is preventing me from finishing a build

    Error Message 1:

    CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct.
    C:/Users/willi/AppData/Local/Android/Sdk\tools\bin\avdmanager.bat list target -c
    stderr[
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.AvdManagerCli.parseSdk(AvdManagerCli.java:328)
    at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:204)
    at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:195)
    Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more
    ]
    stdout[
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.RunAndroidSdkTool (System.String toolName, System.String arguments, Boolean updateCommand, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.ListTargetPlatforms (UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit)
    UnityEditor.Android.AndroidSDKTools.GetTopAndroidPlatformAvailable (UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit)
    UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK+SDKPlatformDetector.GetVersion (UnityEditor.Android.AndroidSDKTools sdkTools)
    UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK+SDKComponentDetector.Detect (UnityEditor.Android.AndroidSDKTools sdkTools, System.Version minVersion, UnityEditor.Android.PostProcessor.ProgressHandler onProgress)
    UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK.EnsureSDKComponentVersion (System.Version minVersion, UnityEditor.Android.PostProcessor.Tasks.SDKComponentDetector detector)
    UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK.EnsureSDKComponentVersion (Int32 minVersion, UnityEditor.Android.PostProcessor.Tasks.SDKComponentDetector detector)
    UnityEditor.Android.PostProcessor.Tasks.CheckAndroidSDK.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Error Message 2:

    Error building Player: CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct.
    C:/Users/willi/AppData/Local/Android/Sdk\tools\bin\avdmanager.bat list target -c
    stderr[
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.AvdManagerCli.parseSdk(AvdManagerCli.java:328)
    at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:204)
    at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:195)
    Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 6 more
    ]
    stdout[
    ]
    exit code: 1

    Error Message 3:

    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    And Finally Error Message 4:

    UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0020e] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:181
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x00065] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:88
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    I have SDK's for android version Jellybean and all the way up to the most recent Oreo Build and i have the most recent JRE and NDK but I still fail my build no matter what I'm too confused for life right now
     
  42. Deleted User

    Deleted User

    Guest

    I'm Now Trying To Create A Power Up System That Gives You 3 Weapons Like In The Extender Tutorial My Only Issue Is I Don't Know How To Switch My Player Between The 2 Different Prefabs For A Duration Of Time Here Are My Scripts So Far

    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.Events;
    7. [Serializable]
    8. public class PowerUp {
    9.     [SerializeField]
    10.     public string name;
    11.     [SerializeField]
    12.     public float duration;
    13.     [SerializeField]
    14.     public UnityEvent startAction;
    15.     [SerializeField]
    16.     public UnityEvent endAction;
    17.     public void End() {
    18.         if (endAction != null) {
    19.             endAction.Invoke();
    20.          
    21.         }
    22.     }
    23.     public void Start() {
    24.         if(startAction != null){
    25.             startAction.Invoke();
    26.         }
    27.     }
    28. }
    29.  
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class PowerUpController : MonoBehaviour {
    6.     public GameObject powerUpPrefab;
    7.     public List<PowerUp> powerUps;
    8.     public Dictionary<PowerUp, float> activePowerUps = new Dictionary<PowerUp, float>();
    9.     private List<PowerUp> keys = new List<PowerUp>();
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         HandleActivePowerUps();
    14.         if (Input.GetKeyDown(KeyCode.LeftShift)) {
    15.             SpawnPowerUp(powerUps[Random.Range(0, powerUps.Count - 1)], new Vector3(3.0f, 0.0f, -3.0f));
    16.         }
    17.     }
    18.     public void HandleActivePowerUps() {
    19.         bool changed = false;
    20.         if (activePowerUps.Count > 0) {
    21.             foreach (PowerUp powerUp in keys) {
    22.                 if (activePowerUps[powerUp] > 0)
    23.                 {
    24.                     activePowerUps[powerUp] -= Time.deltaTime;
    25.                 }
    26.                 else {
    27.                     changed = true;
    28.                     activePowerUps.Remove(powerUp);
    29.                     powerUp.End();
    30.                 }
    31.             }
    32.         }
    33.         if (changed == true) {
    34.             keys = new List<PowerUp>(activePowerUps.Keys);
    35.         }
    36.     }
    37.     public void ActivatePowerUp(PowerUp powerUp) {
    38.         if (!activePowerUps.ContainsKey(powerUp))
    39.         {
    40.             powerUp.Start();
    41.             activePowerUps.Add(powerUp, powerUp.duration);
    42.         }
    43.         else {
    44.             activePowerUps[powerUp] += powerUp.duration;
    45.             keys = new List<PowerUp>(activePowerUps.Keys);
    46.         }
    47.     }
    48.     public GameObject SpawnPowerUp(PowerUp powerUp, Vector3 position) {
    49.         GameObject powerUpGameObject = Instantiate(powerUpPrefab);
    50.         var powerUpBehaviour = powerUpGameObject.GetComponent<PowerUpBehaviour>();
    51.         powerUpBehaviour.controller = this;
    52.         powerUpBehaviour.SetPowerUp(powerUp);
    53.         powerUpGameObject.transform.position = position;
    54.         return powerUpGameObject;
    55.     }
    56. }
    57.  
    58.  
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class PowerUpBehaviour : MonoBehaviour {
    6.     public PowerUpController controller;
    7.     [SerializeField]
    8.     private PowerUp powerUp;
    9.     private Transform tf;
    10.     private void Awake() {
    11.         tf = GetComponent<Transform>();
    12.     }
    13.     private void OnTriggerEnter(Collider other) {
    14.         if (other.gameObject.tag == "Player") {
    15.             ActivatePowerUp();
    16.             gameObject.SetActive(false);
    17.         }
    18.     }
    19.     private void ActivatePowerUp() {
    20.         controller.ActivatePowerUp(powerUp);
    21.     }
    22.     public void SetPowerUp(PowerUp powerUp) {
    23.         this.powerUp = powerUp;
    24.         gameObject.name = powerUp.name;
    25.     }
    26. }
    27.  
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. public class PowerUpActions : MonoBehaviour {
    6.     [SerializeField]
    7.  
    8.     public GameController gameController;
    9.     private PlayerController playerController;
    10.     private PowerUp powerUp;
    11.     public void TripleWeaponStartAction() {
    12.       //Need To Switch Character With Upgraded Weapon Prefab
    13.     }
    14.     public void TripleWeaponEndAction()
    15.     {
    16.       //Need To Switch Back To Regular Player
    17.     }
    18. }
    19.  
     
    Last edited by a moderator: Mar 8, 2018
  43. E2max007

    E2max007

    Joined:
    Jan 18, 2018
    Posts:
    3
    At: 00.35.10 in this video: https://unity3d.com/learn/tutorials...e-shooter-enemies-more-hazards?playlist=17147
    The Teacher/Master (thanks for making them) explains the attempt to separate art and game logic in different game objects.

    Whats the benefit of separating art work and game logic in different game objects? (have parent object with script/physics etc, and a child with the art)
    If you would put it all in one object wont you have the same effect as it sits in different components?

    I am really curious about this.
     
  44. torourke

    torourke

    Joined:
    Mar 9, 2018
    Posts:
    1
    Hi all, I'm having trouble with my bolt prefabs. I followed all the instructions and checked my code but whenever I start the game, a stream of bolts starts to get instantiated and just goes on forever. Any help would be greatly appreciated!

    Code (CSharp):
    1.     public Boundary boundary;
    2.     public GameObject shot;
    3.     public Transform shotSpawn;
    4.     public float fireRate;
    5.  
    6.     private float nextFire;
    7.  
    8.     void Start()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         if (Time.time > nextFire)
    16.         {
    17.             nextFire = Time.time + fireRate;
    18.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    19.         }
    20.     }
    21.  
    Edit for clarity:
    The bolt objects ignore the fireRate variable and instantiate in a steady stream. However, when I remove the Input.GetButton("Fire1") condition from the if statement, the bolts behave as expected. That is, they come out in a steady stream but with timing appropriate for the Time.time > nextFire condition.
     
    Last edited: Mar 9, 2018
  45. charlesbuckley321

    charlesbuckley321

    Joined:
    Jan 9, 2018
    Posts:
    1
    Hi,

    I'm creating the GameController right now, and it won't allow me to drag and drop my asteroid prefab onto 'Hazard', as I'm supposed to be able to. I double-checked the scripts, and they seem to not be the problem, but I have no clue. Thanks in advance.
     
  46. Deleted User

    Deleted User

    Guest

    I'm Still Trying To Make A Power Up For The Ship To Shoot 3 Weapons After You Pickup A PowerUp GameObject I Keep Getting The Error
    NullReferenceException: Object reference not set to an instance of an object
    PowerUp+<PickUp>c__Iterator0.MoveNext () (at Assets/Scripts/PowerUp.cs:86)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    PowerUp:OnTriggerEnter(Collider) (at Assets/Scripts/PowerUp.cs:18)

    Here Are My Scripts:

    Code (CSharp):
    1.  
    2.  
    3. using System;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7. [Serializable]
    8. public class Boundary{
    9.     public float xMin, xMax, zMin, zMax;
    10. }
    11. public class PlayerController : MonoBehaviour {
    12.     public float speed;
    13.     public float defaultSpeed;
    14.     public float tilt;
    15.     public Boundary boundary;
    16.     public GameObject shot;
    17.     public Transform shotSpawn;
    18.     //public SimpleTouchPad touchPad;
    19.     //public SimpleTouchAreaButton areaButton;
    20.     private Quaternion calibrationQuaternion;
    21.     /*
    22.      
    23.         \\Upgrading Player Weapon
    24.         public Transform[] shotSpawns;
    25.     */
    26.     public float fireRate;
    27.     private float nextFire;
    28.     private Rigidbody rb;
    29.     private AudioSource audioSource;
    30.     private void Start (){
    31.         rb = GetComponent<Rigidbody>();
    32.         audioSource = GetComponent<AudioSource>();
    33.         /*
    34.         // For Android Tilt Controlls
    35.         CalibrateAccellerometer();
    36.         */
    37.     }
    38.     private void Update()
    39.     {
    40.         // For Firing On WebGL
    41.         if (Input.GetButton("Fire1") && Time.time > nextFire){
    42.             nextFire = Time.time + fireRate;
    43.             /*
    44.              
    45.                 //Upgrading Player Weapon
    46.                 foreach (var shotSpawn in shotSpawns){
    47.              
    48.                     Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    49.              
    50.                 }
    51.             */
    52.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    53.             audioSource.Play();
    54.      
    55.         }
    56.      
    57.         /* Android UI Button For Firing
    58.         if (areaButton.CanFire() && Time.time > nextFire)
    59.         {
    60.             nextFire = Time.time + fireRate;
    61.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    62.             audioSource.Play();
    63.         }
    64.         */
    65.         // Instantiate(object, position, rotation);
    66.         /*
    67.             // For Android Tilt Controlls
    68.             private void CalibrateAccellerometer()
    69.             {
    70.                 Vector3 accelerationSnapshot = Input.acceleration;
    71.                 Quaternion rotateQuaternion = Quaternion.FromToRotation(new Vector3(0.0f, 0.0f, -0.1f), accelerationSnapshot);
    72.             }
    73.             private Vector3 FixAcceleration(Vector3 acceleration)
    74.             {
    75.                 Vector3 fixedAcceleration = calibrationQuaternion * acceleration;
    76.                 return fixedAcceleration;
    77.             }
    78.         */
    79.     }
    80.     private void FixedUpdate(){
    81.         //Default Input For Web Development
    82.         float moveHorizontal = Input.GetAxis ("Horizontal");
    83.         float moveVertical = Input.GetAxis ("Vertical");
    84.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    85.         rb.velocity = movement * speed;
    86.         /*
    87.      
    88.             // For Android Tilt Controlls
    89.          
    90.             Vector3 accelerationRaw = Input.acceleration;
    91.             Vector3 acceleration = FixAcceleration(accelerationRaw);
    92.             Vector3 movement = new Vector3(acceleration.x, 0.0f, acceleration.y);
    93.         */
    94.         /* Android Touch Controlls
    95.      
    96.         //Vector2 direction = touchPad.GetDirection();
    97.         //Vector3 movement = new Vector3(direction.x, 0.0f, direction.y);
    98.         rb.velocity = movement * speed;
    99.      
    100.         */
    101.         rb.position = new Vector3 (
    102.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    103.             0.0f,
    104.             Mathf.Clamp(rb.position.z , boundary.zMin, boundary.zMax)
    105.         );
    106.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    107.     }
    108.  
    109. }
    110.  
    111.  
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. [System.Serializable]
    6. public class NewBoundary
    7. {
    8.     public float xMin, xMax, zMin, zMax;
    9. }
    10. public class UpgradePlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.     public GameObject shot;
    16.  
    17.  
    18.      
    19.         // Upgrading Player Weapon
    20.         public Transform[] shotSpawns;
    21.  
    22.     public float fireRate;
    23.     private float nextFire;
    24.     private Rigidbody rb;
    25.     private AudioSource audioSource;
    26.     private void Start()
    27.     {
    28.         rb = GetComponent<Rigidbody>();
    29.         audioSource = GetComponent<AudioSource>();
    30.     }
    31.     private void Update()
    32.     {
    33.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    34.         {
    35.             nextFire = Time.time + fireRate;
    36.          
    37.              
    38.                 //Upgrading Player Weapon
    39.                 foreach (var shotSpawn in shotSpawns){
    40.              
    41.                     Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    42.              
    43.                 }
    44.          
    45.             audioSource.Play();
    46.         }
    47.     }
    48.     // Instantiate(object, position, rotation);
    49.     private void FixedUpdate()
    50.     {
    51.         float moveHorizontal = Input.GetAxis("Horizontal");
    52.         float moveVertical = Input.GetAxis("Vertical");
    53.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    54.         rb.velocity = movement * speed;
    55.         rb.position = new Vector3(
    56.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    57.             0.0f,
    58.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    59.         );
    60.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    61.     }
    62. }
    63.  
    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. public class PowerUp : MonoBehaviour {
    7.     public GameObject pickupEffect;
    8.     public float multiplier;
    9.     public float duration;
    10.    private void OnTriggerEnter(Collider other)
    11.     {
    12.         if (other.CompareTag("Player") || other.CompareTag("Player2")) {
    13.      
    14.            StartCoroutine( PickUp(other) );
    15.         }
    16.     }
    17.     /*  Scale Player
    18.  
    19.         private IEnumerator PickUp(Collider player) {
    20.             // Spawn A Cool Effect
    21.             Instantiate(pickupEffect, transform.position, transform.rotation);
    22.             // Apply Effect To Player
    23.             player.transform.localScale *= multiplier;
    24.             GetComponent<MeshRenderer>().enabled = false;
    25.             GetComponent<Collider>().enabled = false;
    26.             // Wait X Ammount Of Seconds
    27.             yield return new WaitForSeconds(duration);
    28.             // Remove Effect
    29.             player.transform.localScale /= multiplier;
    30.             // Remove Power Up Object
    31.             Destroy(gameObject);
    32.         }
    33.     */
    34.     /* Upgrade Health
    35.      
    36.         private IEnumerator PickUp(Collider player) {
    37.             // Spawn A Cool Effect
    38.             Instantiate(pickupEffect, transform.position, transform.rotation);
    39.             // Apply Effect To Player
    40.             PlayerStats stats = player.GetComponent<PlayerStats>();
    41.             stats.health *= multiplier;
    42.             GetComponent<MeshRenderer>().enabled = false;
    43.             GetComponent<Collider>().enabled = false;
    44.             // Wait X Ammount Of Seconds
    45.             yield return new WaitForSeconds(duration);
    46.             // Remove Effect
    47.             stats.health /= multiplier;
    48.             // Remove Power Up Object
    49.             Destroy(gameObject);
    50.              
    51.         }
    52.     */
    53.     private IEnumerator PickUp(Collider player)
    54.     {
    55.         // Spawn A Cool Effect
    56.         Instantiate(pickupEffect, transform.position, transform.rotation);
    57.         // Apply Effect To Player
    58.         if (player.CompareTag("Player")) {
    59.             GetComponent<UpgradePlayerController>().fireRate = 500000000f;
    60.             GetComponent<PlayerController>().fireRate = 0.25f;
    61.         }
    62.         // Remove Power Up Object Mesh And Collider
    63.         GetComponent<MeshRenderer>().enabled = false;
    64.         GetComponent<Collider>().enabled = false;
    65.         // Wait X Ammount Of Seconds
    66.         yield return new WaitForSeconds(duration);
    67.         // Remove Effect
    68.         if (player.CompareTag("Player"))
    69.         {
    70.             GetComponent<UpgradePlayerController>().fireRate = 0.25f;
    71.             GetComponent<PlayerController>().fireRate = 500000000f;
    72.         }
    73.         // Remove Power Up Object
    74.         Destroy(gameObject);
    75.     }
    76. }
    77.  
    78.  
    79.  
    Been Working At It For Days Now And It Is Driving Me Nuts Lol Can Anyone Help?
     
  47. kaimanawakilla

    kaimanawakilla

    Joined:
    Mar 13, 2018
    Posts:
    4
    hi did you find the answer? im up2 this stage now as well! im guessing just use the default setting as when you try select the other settings nothing has been imported to use anyway ....
     
  48. kaimanawakilla

    kaimanawakilla

    Joined:
    Mar 13, 2018
    Posts:
    4
    hi if you have followed all steps you may find that your missing one thing in your code that is misplaced added or not added by mistake...im sorry i cant be more helpful as im just learning as well...i usually go to other projects if im getting frustrated with my code etc then come back with a fresh mind later on ....good luck anyway :)
     
  49. Wikimrar

    Wikimrar

    Joined:
    Mar 14, 2018
    Posts:
    1
     
  50. E2max007

    E2max007

    Joined:
    Jan 18, 2018
    Posts:
    3
    I think you can use any platform for the tutorial. Web player is gone, but WebGL is about the same.