[英]Creating game in C# Unity3D and it doesn't work
my snippets doesn't work in vscode, i use Unity 3.5 and VScode lastest version and public class not show in gameobject there is my code:我的片段在 vscode 中不起作用,我使用 Unity 3.5 和 VScode 最新版本,公共 class 没有显示在游戏对象中,有我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class kontrol : MonoBehaviour
{
public float berat, tinggiLoncat;
public private void OnParticleCollision(GameObject bird) {
};
// Start is called before the first frame update
void Start()
{
}
void OnMouseDown() {
bird.GetComponent<Rigidbody2D> ().gravityScale = berat;
bird;GetComponent<Rigidbody2D> ().velocity = new Vector2 ( bird;GetComponent<Rigidbody2D>().velocity.x, tinggiLoncat);
}
// Update is called once per frame
void Update()
{
}
}
This isnt working because you have many syntax errors and the script isn't compiling so you cant add it obviously.这不起作用,因为您有许多语法错误并且脚本未编译,因此您无法明显添加它。
public private void OnParticleCollision(GameObject bird) { // Public Private? Choose one!
}; //no semicolon after methods
bird.GetComponent<Rigidbody2D> ().gravityScale
bird;GetComponent<Rigidbody2D> ().velocity //why are you using a semicolon, you did it right in the first place.
GetComponent
is expensive. GetComponent
很昂贵。 Use it once in Awake
or Start
, and save the reference.Awake
或Start
中使用一次,然后保存参考。 For example:class SomeComponent: MonoBehaviour {
Rigidbody rb;
void Awake() {
rb = GetComponent<Rigidbody>();
}
void Update() {
// do something with rb
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.