英文:
I just started learning unity and I can't seem to figure it out, what did I do wrong?
问题
I understand that you want the code to be translated. Here's the translated code without any additional content:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawnScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float timer = 0;
// 在第一帧之前调用
void Start()
{
SpawnPipe();
}
// 每帧调用一次
void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
SpawnPipe();
timer = 0;
}
}
void SpawnPipe()
{
Instantiate(pipe, transform.position, transform.rotation);
}
}
If you have any more code to translate or need further assistance, please let me know.
英文:
So, I was following a tutorial on unity and things were going fine but then I got the error 'Assets\PipeSpawnScript.cs(26,18): warning CS8321: The local function 'spawnPipe' is declared but never used' and I can't seem to figure it out what to do, I checked the code and compared it to the code in the tutorial but it was the exact same, here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawnScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float timer = 0;
// Start is called before the first frame update
void Start()
{
void spawnPipe();
}
// Update is called once per frame
void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
void spawnPipe();
timer = 0;
}
}
void spawnPipe()
{
Instantiate(pipe, transform.position, transform.rotation);
}
}
Here is the link to the tutorial: https://www.youtube.com/watch?v=XtQMytORBmM
And I'm using version 2021.3.24f1
It should make a pipe as soon as the player starts the game (Note: I'm recreating Flappy Bird)
答案1
得分: 4
This declares a local function which is never called:
void Start()
{
void spawnPipe() { }
}
With void spawnPipe();
you will get even another error telling you that the local function needs a body.
This calls an existing method:
void Start()
{
spawnPipe();
}
Remove the void
keyword!
英文:
This declares a local function which is never called:
void Start()
{
void spawnPipe() { }
}
With void spawnPipe();
you will get even another error telling you that the local function needs a body.
This calls an existing method:
void Start()
{
spawnPipe();
}
Remove the void
keyword!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论