- Home /
cannot show my hazard in space shooter
hi gays~
I follow the space shooter in unity and have problem now
I finish chapter 11 of space shooter which is explosions and then I cannot show hazard in play mode end of the came controller part
i don't know why......T^T...
gays please help me
I made Asteroid prefab and then deleted of Asteroid game object in hierarchy also my asteroid prefab has 'random rotator' 'mover' 'destroy by contact' scripts and 'rigid body' and 'capsule colander'.
I exactly wrote c# script from tutorial and did not copy 'done' scripts
My game controller object has game controller script and include asteroid prefab ..........
i really do not have any idea, why i cannot show may Asteroid in play move
My space shooter does not have any error and warning
help me..... pleaze
This is my came controller script
using UnityEngine; using System.Collections;
public class GameConroller : MonoBehaviour {
public GameObject hazard;
public Vector3 spawnValues;
void start(){
SpawnWaves ();
}
void SpawnWaves()
{
Vector3 spawnPosition = new Vector3 (Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
}
}
Answer by Cherno · May 04, 2015 at 08:20 AM
Try
GameObject newSpawn = Instantiate (hazard, spawnPosition, spawnRotation) as GameObject;
thanks for your answer I tried yours, but I have error. like this " Assets/Scripts/GameConroller.cs(29,81): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
what is that.......?
before use "as Gameobject" I did not have error message and only did not show hazard without any warning and error but after use "as Gameobject" in my code i have error......
please help me ...
Pardon me, my bad. Of course you need to create an appropriate variable to receive the Instantiate function's return type, which is GameObject. So the line needs to be
GameObject newSpawn = Instantiate (hazard, spawnPosition, spawnRotation) as GameObject;
I changed my comment above to reflect this.
Answer by OfficeCyber · May 07, 2015 at 06:18 AM
Did you assigned the prefab in the inspector?
Test your prefab pulling it directly to the scene. Is it ok?
Have you checked the values of the spawn positions?
When in play mode, in the Scene view from a far point, can you see the prefab been instantiated???
Your answer
Follow this Question
Related Questions
Space Shooter: Asteroids not being destroyed 1 Answer
Want Ships & Bullets to transform relative to Camera. 2 Answers
Javascript Fatal Content Error from Space Shooter tutorial in Chrome web build 1 Answer
why the boundary is not working? 0 Answers
Why showing bugs in sample code of space shooting project 0 Answers