Search Unity

Space Shooter Tutorial Q&A

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

  1. wakuwalt7

    wakuwalt7

    Joined:
    Oct 19, 2015
    Posts:
    6
    Hi, sorry for bothering you with a (maybe) silly issue,i following your tutorials from some time (first the roll-a-ball that goes perfectly and now this course) but i'm at the "ending a game" section, and i don't know why, but...
    the game doesn't want to end.
    I've wrote the code as it's written but when it have to test it, there's not text, or even an ending!

    Code (csharp):
    1.  
    2. [code=CSharp]using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GameController : MonoBehaviour {
    6.  
    7.     public GameObject hazard;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.  
    14.     public GUIText scoreText;
    15.     public GUIText restartText;
    16.     public GUIText gameOverText;
    17.  
    18.     private bool gameOver;
    19.     private bool restart;
    20.     private int score;
    21.  
    22.     void Start () {
    23.         gameOver = false;
    24.         restart = false;
    25.         restartText.text = "";
    26.         gameOverText.text = "";
    27.         score = 0;
    28.         UpdateScore();
    29.         StartCoroutine (SpawnWaves());
    30.     }
    31.  
    32.     void Update()
    33.     {
    34.         if(restart)
    35.         {
    36.             if(Input.GetKeyDown (KeyCode.R) )
    37.             {
    38.                 Application.LoadLevel (Application.loadedLevel);
    39.             }
    40.         }
    41.     }
    42.  
    43.     IEnumerator SpawnWaves ()
    44.     {
    45.         yield return new WaitForSeconds(startWait);
    46.         while(true)
    47.         {
    48.             for (int i = 0; i < hazardCount; i++)
    49.             {
    50.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    51.                 Quaternion spawnRotation = Quaternion.identity;
    52.                 Instantiate(hazard, spawnPosition, spawnRotation);
    53.                 yield return new WaitForSeconds(spawnWait);
    54.             }
    55.             yield return new WaitForSeconds(waveWait);
    56.  
    57.             if (gameOver)
    58.             {
    59.                 restartText.text = "press R for restart";
    60.                 restart = true;
    61.                 break;
    62.             }
    63.         }
    64.     }
    65.  
    66.     public void AddScore(int newScoreValue)
    67.     {
    68.         score += newScoreValue;
    69.         UpdateScore();
    70.     }
    71.  
    72.     void UpdateScore()
    73.     {
    74.         scoreText.text = "score: " + score;
    75.     }
    76.  
    77.     public void GameOver ()
    78.     {
    79.         gameOverText.text = "Game Over!";
    80.         gameOver = true;
    81.     }
    82. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContact : MonoBehaviour {
    5.  
    6.     public GameObject explosion;
    7.     public GameObject playerExplosion;
    8.     public int scoreValue;
    9.     private GameController gameController;
    10.  
    11.     void Start()
    12.     {
    13.         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    14.         if (gameControllerObject != null)
    15.         {
    16.             gameController = gameControllerObject.GetComponent<GameController>();
    17.         }
    18.         if (gameController == null)
    19.         {
    20.             Debug.Log("Cannot find 'GameController' script");
    21.         }
    22.     }
    23.  
    24.     void OnTriggerEnter(Collider other)
    25.     {
    26.         if (other.tag == "Boundary") {
    27.             return;
    28.         }
    29.         Instantiate(explosion, transform.position, transform.rotation);
    30.         if (other.tag == "Player")
    31.         {
    32.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    33.             Debug.Log("if you read me, there's no way out"); //added a log for testing purpose, also this doesn't appear!)
    34.             gameController.GameOver ();
    35.         }
    36.         gameController.AddScore(scoreValue);
    37.         Destroy(other.gameObject);
    38.         Destroy(gameObject);
    39.     }
    40. }
    Also, in text box when i start the game test, at first the text appears:


    But when the player gets crushed, the game doesn't recognize that the player is dead (i think) and don't activate the game over and restart script...



    I'm not sure of what i do wrong, but a little helpful! Thank you very much for reading this!
     
    Last edited: Nov 2, 2015
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    First question: is the player tagged as "Player"?
     
    wakuwalt7 likes this.
  3. speedlight

    speedlight

    Joined:
    Sep 17, 2015
    Posts:
    5
    Hi great comunity!
    I finish the tutorial with the mobile version, all is working perfect but I want to make a change.
    How can I move the player not with the touchpad area but move the ship with the finger in the entire play area.
    I tried to make the touch area the whole screen with and a fire button, is working fine the way the tutorial show, right now with the touchpad version, if I touch or click the screen and move to the right the ship keeps moving to the right, that I want to move it only the distance my finger si moving.. can u help with some guidance please?

    Ps.: sorry for my english, not my native lang :D
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Just make the area with the touch panel script bigger. Just be aware that you will start to conflict with your fire button, so you'll have to adjust for that.
     
  5. wakuwalt7

    wakuwalt7

    Joined:
    Oct 19, 2015
    Posts:
    6
    No, it wasn't! What a dumb error lol
    Now it works, thanks!
     
    Last edited: Nov 3, 2015
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  7. SolidWhiteTiger

    SolidWhiteTiger

    Joined:
    Oct 26, 2015
    Posts:
    4
    Gotcha, makes sense, so we would definitely need to use the player controller script for say an FPS? And would it also make sense to make two diff audio clips, one for the 'bang' (for player controller script) and one for the 'whizz' (for the bolt/bullet)?
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yes. And you can do things like add Doppler to the projectile, but use distance to muffle the sound of the gun.
     
  9. speedlight

    speedlight

    Joined:
    Sep 17, 2015
    Posts:
    5
    Yes I tried that, but Im looking for a way to make the part I wrote:
    "... right now with the touchpad version, if I touch or click the screen and move to the right the ship keeps moving to the right, that I want is to move it only the distance my finger is moving.."

    Cheers.
     
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I may be thick, by I don't understand what behaviour you are looking for...

    Can you try to describe it in detail.
     
  11. kadynowski

    kadynowski

    Joined:
    Nov 4, 2015
    Posts:
    2
    Hello !
    I have problem in creating a script for explosion meteor and player. I do everything like in tutorial and I even copy and paste all script. But when I switch in to unity I see warning near the script on tle right panel : " The associated script can not be loaded. Please fix any compile errors and assign a valid script."
    I dont have any error on console....
    Help :(
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Hmmm. No errors at all in the console? This is hard to understand. That warning is usually indicating a compile error. Realise that this error can be in any script. All scripts must compile for this to work.
     
  13. kadynowski

    kadynowski

    Joined:
    Nov 4, 2015
    Posts:
    2

    Im sorry its fine now. :) But thank you for you very fast respond ! ( I copy one line of code twice and I didnt notice that... )
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yay! Glad it's all working.
     
  15. rckkk

    rckkk

    Joined:
    Oct 8, 2015
    Posts:
    6
    Help please:

    UnityException: GameObject has undefined tag!
    UnityEngine.Component.get_tag () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineComponentBindings.gen.cs:160)
    DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:37)


    my Player is tagged with Player i don't know why i'm having this error.
     
  16. MrOtheninGirard

    MrOtheninGirard

    Joined:
    Sep 3, 2015
    Posts:
    2
    Hi! I'm working through the Space Shooter tutorial with my students. We're using JavaScript as our scripting language. In the Unity 5 Upgrade guide, they give the syntax for accessing the rigidbody component for C#, but not for JS. Is this correct?

    class Boundary
    {
    var xMin : float;
    var xMax : float;
    var zMin : float;
    var zMax : float;
    }

    var speed : float;
    var tilt : float;
    var boundary : Boundary;
    var rb: GetComponent<Rigidbody>();

    function FixedUpdate () {
    var moveHorizontal : float= Input.GetAxis ("Horizontal");
    var moveVertical : float= Input.GetAxis ("Vertical");

    var movement : Vector3= new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement * speed;

    rb.position = new Vector3
    (
    Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    );

    rb.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    }
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Double check both the tags on all,of your objects (Player, Boundary, etc.), but also check the tags and layers list to see if they are properly defined.
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please use code tags when posting code on this forum.
     
  19. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I believe this line:
    Code (JavaScript):
    1. var rb: GetComponent<Rigidbody>();
    ... Should have a dot in it:
    Code (JavaScript):
    1. var rb: GetComponent.<Rigidbody>();
    ... But when using unity script, you should check the documentation.
     
  20. aidenlgrayson

    aidenlgrayson

    Joined:
    Oct 23, 2015
    Posts:
    5
    Sure,
    So when I am firing shots I get a clone of the shots, so it begins as a bolt, and then bolt(clone) then bolt(clone)(clone). Which isnt like the video. And also when all of the shots are destroyed by the boundary I can no longer shoot and I get the error saying that the game object was destroyed but I am still trying to access it.
    Thanks

    {EDIT}
    Problem solved
    Change shot = Instantiate(shot) as GameObject;
    to
    Rigidbody clone;
    clone = Instantiate(shot, transform.position, transform.rotation) as Rigidbody;
     
    Last edited: Nov 6, 2015
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Aiden - yes, you've got it. In the first case, you are replacing your reference to the prefab, which is held in the variable shot with a reference to the newly instantiated GameObject. In the second case, you've created a new variable (clone), so it's being held with its own reference.
     
  22. xFrost96x

    xFrost96x

    Joined:
    Nov 7, 2015
    Posts:
    3
    Hi I am using Unity 5.2.2f1 ,the bolt prefabs seems to be destroy(or missing) whenever it leaves the boundary. Is there any solution to fix this??

    Edited:
    Problem Solved:)
     
    Last edited: Nov 7, 2015
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Great! Glad all is good!
     
  24. uncronopio

    uncronopio

    Joined:
    Nov 8, 2015
    Posts:
    5
    I have a doubt: after adding sound effects and reducing the bolts' volume, I noticed the few first shots are noticeably louder than the rest. Why is that? Did I do something wrong?
     
  25. blywulf

    blywulf

    Joined:
    Nov 9, 2015
    Posts:
    1
    Hey I am not sure if you are aware of this, but there are missing files. Specifically there are two models that are not on the list in the asset list, that are on yours in the video tuitorial? see: https://www.assetstore.unity3d.com/en/#!/content/13866
    any way to solve the problem of missing assets? I looked around and deleted everything and started over and re downloaded the assets, still missing stuff. Tuitorials are kind of useless if they can't even be done!
     
  26. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning, what assets/models are they?
    were they prefabs or just models?
     
  27. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is strange! I can't imagine why the volume would change if you are instantiating the same object.

    Are you doubly-sure that you've set the audio volume on the audio source on the prefab in the project view? And that you are definitely using this prefab as the reference to shot?

    Also, are you using "2D Sound"? Not 3D? This shouldn't make a big difference, but if you move farther away from the audio listener (on the camera) this could make a difference to 3D sound. I wouldn't have thought it would have made a *huge* (or even noticeable) difference...

    Start tracking down any and all details on how the sound is working as we'll work through it.
     
  28. wakuwalt7

    wakuwalt7

    Joined:
    Oct 19, 2015
    Posts:
    6
    Hi, i've found another issue when making the game.
    When i shoot to the enemies, they exploding also using the player explosion even if the player wasn't hit!

    minghie.PNG

    Items are all tagged correctly (Player is "Player" , Enemies are "Enemy" etc.) and script that command them are wrote correctly (i made a little error at first time writing Player instead of Enemy, but then i fixed it)...

    Code (CSharp):
    1. //GameController script
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class GameController : MonoBehaviour {
    7.  
    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.  
    15.     public GUIText scoreText;
    16.     public GUIText restartText;
    17.     public GUIText gameOverText;
    18.  
    19.     private bool gameOver;
    20.     private bool restart;
    21.     private int score;
    22.  
    23.     void Start () {
    24.         gameOver = false;
    25.         restart = false;
    26.         restartText.text = "";
    27.         gameOverText.text = "";
    28.         score = 0;
    29.         UpdateScore();
    30.         StartCoroutine (SpawnWaves());
    31.     }
    32.  
    33.     void Update()
    34.     {
    35.         if(restart)
    36.         {
    37.             if(Input.GetKeyDown (KeyCode.R) )
    38.             {
    39.                 Application.LoadLevel (Application.loadedLevel);
    40.             }
    41.         }
    42.     }
    43.  
    44.     IEnumerator SpawnWaves ()
    45.     {
    46.         yield return new WaitForSeconds(startWait);
    47.         while(true)
    48.         {
    49.             for (int i = 0; i < hazardCount; i++)
    50.             {
    51.                 GameObject hazard = hazards[Random.Range (0, hazards.Length)];
    52.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    53.                 Quaternion spawnRotation = Quaternion.identity;
    54.                 Instantiate(hazard, spawnPosition, spawnRotation);
    55.                 yield return new WaitForSeconds(spawnWait);
    56.             }
    57.             yield return new WaitForSeconds(waveWait);
    58.  
    59.             if (gameOver)
    60.             {
    61.                 restartText.text = "press R for restart";
    62.                 restart = true;
    63.                 break;
    64.             }
    65.         }
    66.     }
    67.  
    68.     public void AddScore(int newScoreValue)
    69.     {
    70.         score += newScoreValue;
    71.         UpdateScore();
    72.     }
    73.  
    74.     void UpdateScore()
    75.     {
    76.         scoreText.text = "score: " + score;
    77.     }
    78.  
    79.     public void GameOver ()
    80.     {
    81.         gameOverText.text = "Game Over!";
    82.         gameOver = true;
    83.     }
    84. }
     
  29. Aperosuz

    Aperosuz

    Joined:
    Nov 9, 2015
    Posts:
    1
    Hi
    I'm on Unity 5.2 and I have a problem with my GUI Text for the score ...
    I never can't see it, in the scene or in the game, my GUI Text is invisible
    and I try it was on the limit of the screen ...
    And second problem, if i put X=0 and Y=1 my GUIText is on the middle of my screen (but already invisible)



    Someone know how i can fix this ?

    Thanks for your help
     
  30. duke1294

    duke1294

    Joined:
    Nov 9, 2015
    Posts:
    1
    I can't seem to set the boundary for moving the player.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Boundary
    5. {
    6.     public float xMin, xMax, zMin, zMax;
    7. }
    8.  
    9. public class PlayerController : MonoBehaviour
    10. {
    11.     public float speed;
    12.     public float tilt;
    13.     public Boundary boundary;
    14.     private Rigidbody rb;
    15.    
    16.     void FixedUpdate ()
    17.     {
    18.         rb = GetComponent<Rigidbody>();
    19.         float moveHorizontal = Input.GetAxis ("Horizontal");
    20.         float moveVertical = Input.GetAxis ("Vertical");
    21.        
    22.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    23.         rb.velocity = movement * speed;
    24.        
    25.         rb.position = new Vector3
    26.             (
    27.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    28.                 0.0f,
    29.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    30.                 );
    31.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    32.     }
    33. }
    It looks right but the console says to look at line 25. Please tell me what's wrong.
     
  31. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening @duke1294 ,

    you need to put the System.Serializable above the Boundary class declaration.
    Code (CSharp):
    1. [System.Serializable]
    2. public class Boundary
    3. {
    4.     public float xMin, xMax, zMin, zMax;
    5. }
    also, just as a little bit of a side tip, where you are finding your RigidBody component in the FixedUpdate function, its grabbing this each FixedUpdate iteration. although it wont have an impact on a game this size, its not a bad habit to get into moving forward to find and set this rb variable once if you can.

    if you pop it into a Start function like below just above your FixedUpdate, it will only find it once and set the rb reference, and you can still keep on using it as you are.
    Code (CSharp):
    1. private Rigidbody rb;
    2.  
    3.     void Start()
    4.     {
    5.         rb = GetComponent<Rigidbody>();
    6.     }
    7.  
    8.     void FixedUpdate ()
     
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If the Enemies explode using the player's explosion, then you probably dragged the wrong prefab into the slot in the inspector. Replace the reference with the enemy's explosion prefab.
     
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you tried the note in the original (first) post of this q&a thread re: GUItext?
     
  34. WhySoSeriousGuys

    WhySoSeriousGuys

    Joined:
    Oct 28, 2015
    Posts:
    18
    Hello, is there a way to instantiate a prefab to be a child of my Player game object? I want to spawn a shield for my player but whenever i try it with
    Code (csharp):
    1.  
    2. Instantiate (shield, spawnPosition, spawnRotation);
    3.         shield.transform.parent = GameObject.Find ("Player").transform;
    4.  
    It keeps spawning as new game object instead of spawning as a player child

    Any ideas how to spawn my shield as a player's child?
     
  35. uncronopio

    uncronopio

    Joined:
    Nov 8, 2015
    Posts:
    5
    Hi Adam,

    Sound is 2D. The sound effect is (as I believe is indicated in the tutorial) in the player GameObject. My prefab "bolt" has no sound components. Bolts are indeed created using the prefab. Perhaps this screen print helps?

    After some playing around I noticed the sound is not lowered after a given time, but after an asteroid is destroyed! The effect is also temporary, so I guess this must regard how multiple sounds interact with each other? I'm sorry if I touched something I should not have!
     

    Attached Files:

  36. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    A couple of things...

    First, to the "meat" of it: Do you really need to instantiate and destroy the shield?

    I would suggest simply making the shield as a child of the player in the hierarchy during edit-time, rather than trying to instantiate it (and destroy it) from a prefab at runtime. Then you can take a reference to the shield with:
    Code (csharp):
    1. public GameObject shield;
    ... and then drag the reference to the GameObject in the inspector.

    In your game code you can have something like:
    Code (csharp):
    1. void ToggleShield (bool toggleFlag)
    2. {
    3.      shield.SetActive (toggleFlag);
    4. }
    Now, you will be able to turn the shield on by simple sending:
    Code (csharp):
    1. ToggleShield (true);
    Turning it off would be simply sending false instead of true.

    With this, all that's left up to you is do work out the logic of when and how you toggle the shield. Be aware that if you wanted to, say, turn the shield on using a Button element from the UI system, you would have to make ToggleShield a public function.

    -

    How can I use a scenario where I set the parent?

    Using Instantiate () by itself (not your code specifically) is saying to Unity: "please add my Object into the scene at this Position and this Rotation. The code does nothing with parenting or the location of the object in the hierarchy. To change the parenting in the hierarchy, your code will need to have a reference to an object to parent the newly instantiated item to.

    You could have a reference to the player ship's Transform:
    Code (csharp):
    1. public Transform playerTransform;
    ... and then drag a reference to any Transform (by dragging the GameObject into the Transform field).

    Later in code you can say:
    Code (csharp):
    1. GameObject shield = Instantiate (shield, playerTransform.position, playerTransform.roatation) as GameObject;
    2. shield.transform.SetParent (playerTransform);
    As you can see, I've used SetParent here. It might be worth taking a look at the page for SetParent:
    http://docs.unity3d.com/ScriptReference/Transform.SetParent.html

    It's a little different, and as noted you can still use:
    Code (csharp):
    1. shield.transform.parent = playerTransform;
    but I think SetParent is more versatile, and not a bad habit it get into using.

    -

    Now - why didn't your code work?

    With this code:
    Code (csharp):
    1. Instantiate (shield, spawnPosition, spawnRotation);
    2. shield.transform.parent = GameObject.Find ("Player").transform;
    3.  
    ... what is shield?

    The variable shield holds a reference to the prefab object in your project view. This code is trying to set the prefab reference's parent to the player's transform, not the newly instantiated shield object.

    The code would have to take a reference to the newly instantiated GameObject and then set it to the player's Transform:
    Code (csharp):
    1. Transform newShieldClone = Instantiate (shield, spawnPosition, spawnRotation) as Transform;
    2. newShieldClone.parent = GameObject.Find ("Player").transform;
    3.  
    However, this code requires a GameObject.Find() every time you activate your shield.

    Why not cache this? You can either do it with the public/dragged reference way of doing it above, or, make the playerTransform variable private and get the reference when the game starts:
    Code (csharp):
    1. void Awake ()
    2. {
    3.      playerTransform = GameObject.Find ("Player").transform;
    4. }
    Make sense?
     
    OboShape likes this.
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If you play two identical sounds at the same time, their waves forms will add together making a louder sound. Double check which sounds are being activated at what time and double check that the correct Audio Clips are referenced in the appropriate Audio Source.
     
  38. uncronopio

    uncronopio

    Joined:
    Nov 8, 2015
    Posts:
    5
    References are correct, and bolts have some refresh time so they cannot be simultaneous! On top of that, the effect does not depend on shooting frequency (only on hitting an asteroid).
     
  39. WhySoSeriousGuys

    WhySoSeriousGuys

    Joined:
    Oct 28, 2015
    Posts:
    18
    Right now I have an UI for shield and a shield just hiding at the start of the game and appearing after collecting shield powerup BUT:
    The first time my shield works fine. but after I try to collect my powerup second time my shield appears at 0 hp and just dissapears after 1 shot.
    I tried to refresh health at pickup but it doesn't work, so I'm trying now to instantiate new shield whenever I get new powerup and just destroy shieldui and shield object so new one can be created at second pickup.

    That is why I'm trying new approach :v
    Right now I'm getting overwhelmed by size of my project and I'm trying to figure this out with smallest effort and don't screw everything up xD
     
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you post your shield code?
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you look at what's happening when you destroy an asteroid?

    If things get really tough, you may want to learn how to put Monodevelop into debugging mode, and step through all the phases that are happening in your game until you spot the issue.
     
  42. wakuwalt7

    wakuwalt7

    Joined:
    Oct 19, 2015
    Posts:
    6
    ]
    tried it, but it gave me the same problem:
    00.PNG
    00.PNG
    (all the explosion came from the assets prefab folder).
    Thinking that the problem was from the player explosion, i've changed it with each enemy explosion, the explosion changed (obviously) but the problem is still here...



    tried to change it in every way, but i don't know how to do!
     

    Attached Files:

    • 01.PNG
      01.PNG
      File size:
      44.4 KB
      Views:
      758
    Last edited: Nov 10, 2015
  43. WhySoSeriousGuys

    WhySoSeriousGuys

    Joined:
    Oct 28, 2015
    Posts:
    18
    Ok I did this. Had to just put my shieldhp script into player instead of shield, so that whenever my shield goes off my script won't break.
    So easy, yet 3 hours of my life lost on that stupid S*** xD

    btw. my shield script is from: (with some tweaks)
    Code (csharp):
    1. http://unity3d.com/learn/tutorials/projects/survival-shooter/player-health?playlist=17144
    but I can post it if you want it
     
  44. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    ...

    Can you post your code (sing code-tags please!) so we can look at what you've written?

    Also - did you intend for the hazards to be spawned inside the game area?
     
  45. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    o.0? Is there shield code in Survival Shooter?
     
  46. WhySoSeriousGuys

    WhySoSeriousGuys

    Joined:
    Oct 28, 2015
    Posts:
    18
    Just health ui with health script xD so I just made some changes and voila... shield code :D
    it's like a second hp bar for me... and I've got something like this in destroybycontact:
    Code (csharp):
    1.  
    2. if (shield_active == true)
    3. subtract "shield_hp"
    4. else
    5. subtract "player_hp"
    6.  
    so i've got
    PlayerHealth.cs
    ShieldHealth.cs
    and also BossHealth.cs

    and in PlayerController.cs I've got some voids like
    Code (csharp):
    1.  
    2. public void TurnONShield()
    3. {
    4. shieldobj.SetActive (true); //shield object
    5. shieldui.SetActive (true); //UI slider with shield values
    6. shieldON = true; //bool statement for my damage controll
    7. shieldHealth.Fullshield (); //healing shield to full hp whenever i woud pick up new shield powerup
    8.  
    9. }
    10.  
     
    Last edited: Nov 10, 2015
  47. WhySoSeriousGuys

    WhySoSeriousGuys

    Joined:
    Oct 28, 2015
    Posts:
    18
    Do you guys have any ideas how to approach homing missiles?
    I supose I would need some AI for them to search for enemies, right?
    I would like to make some RightClick missiles with big cooldown:oops:

    #edit
    Ok found some js script and it's working like a charm :d you can ignore my post
     
    Last edited: Nov 11, 2015
  48. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Say, can you post the link to the script?
     
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Looks ok... What's not working? That's not a bad approach... Let's get it to work.
     
  50. uncronopio

    uncronopio

    Joined:
    Nov 8, 2015
    Posts:
    5
    Honestly though, it is not such an important bug (specially since I followed the tutorial just as to learn). But then again, learning more debugging techniques may be a good learning exercise as well... so I may do it. Thanks for the help!