"Identifier Expected" 错误?
"Identifier Expected" error?
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
var totalhealth = 100;
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
function Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
我在脚本中得到一个 "Identifier Expected",它在
行中说
function OnTriggerEnter(other : Collider) {
有什么帮助吗?
您使用的 C# 方法语法不正确。 Unity 支持多种用户代码语言。也许您从其他语言复制了一个示例?
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
应该更接近
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
我终于明白了。而且我不再有编译器错误了。
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
public float totalhealth = 100;
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
void Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
@EricJ 谢谢你帮助我。 :)
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
var totalhealth = 100;
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
function Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
我在脚本中得到一个 "Identifier Expected",它在
行中说function OnTriggerEnter(other : Collider) {
有什么帮助吗?
您使用的 C# 方法语法不正确。 Unity 支持多种用户代码语言。也许您从其他语言复制了一个示例?
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
应该更接近
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
我终于明白了。而且我不再有编译器错误了。
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
public float totalhealth = 100;
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
void Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
@EricJ 谢谢你帮助我。 :)