[英]Bullets not showing in game view in Unity
I'm making a "space shooter" game in Unity and here is my problem;我正在 Unity 中制作“太空射击”游戏,这是我的问题;
When the spaceship fires, the bullets are created.当宇宙飞船开火时,会产生子弹。 I can see them on the hierarchy screen, but the bullets are not visible in the "game view".
我可以在层次结构屏幕上看到它们,但在“游戏视图”中看不到项目符号。 When I switch to the "Scene view" and check it, I see that the bullets are there and moving at the top layer.
当我切换到“场景视图”并检查它时,我看到子弹在那里并在顶层移动。 Here are what I've done so far:
以下是我到目前为止所做的:
*Raised the sorting layer of the bullets (didn't work) *提高了子弹的排序层(没用)
*Raised the sorting layer of the spaceship (didn't work) *升了飞船的分拣层(没用)
*I turned off the parallax effect on my camera (there was only blank screen and spaceship and it didn't work) *我关闭了相机上的视差效果(只有黑屏和宇宙飞船,它不起作用)
*I checked the layers from the scene screen. *我从场景屏幕检查了图层。 (Everything is as it should be but still hasn't worked)
(一切都应该是,但仍然没有工作)
In addition, I placed a bullet from my prefabs in the scene.此外,我在场景中放置了我的预制件中的子弹。 I can see that bullet when I run the game, but the bullets I shoot by pressing the space key are not visible.
我在运行游戏时可以看到那个子弹,但是我按空格键射出的子弹是不可见的。
Screenshots of the problem:问题截图:
The code I use is:我使用的代码是:
PlayerController:玩家控制器:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5f;
private float min_Y = -4.2f, max_Y = 4.6f;
private float min_Z = -.8f, max_Z = -.6f;
[SerializeField]
private GameObject PlayerBullet;
[SerializeField]
private Transform AttackPoint;
private void Start()
{
}
private void Update()
{
MovePlayer();
Attack();
}
void MovePlayer()
{
if(Input.GetAxisRaw("Vertical") > 0f)
{
Vector3 temp = transform.position;
Quaternion temp2 = transform.rotation;
temp.y += speed * Time.deltaTime;
temp2.z += speed * Time.deltaTime;
if (temp2.z > max_Z)
temp2.z = max_Z;
if (temp.y > max_Y)
temp.y = max_Y;
transform.rotation = temp2;
transform.position = temp;
}
else if(Input.GetAxisRaw("Vertical") < 0f)
{
Quaternion temp2 = transform.rotation;
Vector3 temp = transform.position;
temp.y -= speed * Time.deltaTime;
temp2.z -= speed * Time.deltaTime;
if (temp2.z < min_Z)
temp2.z = min_Z;
if (temp.y < min_Y)
temp.y = min_Y;
transform.rotation = temp2;
transform.position = temp;
}
else
{
Quaternion temp2 = transform.rotation;
if(temp2.z > -0.71f)
{
temp2.z -= speed/2 * Time.deltaTime;
if (temp2.z < -0.71f)
temp2.z = -0.71f;
}
else if (temp2.z < -0.71f)
{
temp2.z += speed/2 * Time.deltaTime;
if (temp2.z > -0.71f)
temp2.z = -0.71f;
}
transform.rotation = temp2;
}
}
void Attack()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(PlayerBullet, AttackPoint.position, Quaternion.identity);
}
}
}
BulletScript:子弹脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
private float speed = 7f;
private float DeactivateTimer = 3f;
private void Start()
{
}
private void Update()
{
Move();
}
void Move()
{
Vector3 temp = transform.position;
temp.x += speed * Time.deltaTime;
transform.position = temp;
}
}
If anyone can help me I would be appreciated...如果有人可以帮助我,我将不胜感激......
Solved it.解决了。 The created bullets has -9 in transform.z.
创建的子弹在 transform.z 中有 -9。 Fixed it replacing them with 0. Such a stupid msitake...
修复了它用 0 替换它们。这样一个愚蠢的 msitake ......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.