[英]Showing error in CS1002 and CS0116 in C# script in Unity Engine
[英]unity Assets\script\Produce.cs(10,20): error CS1002: ; expected resolution
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
trigger Square.AddComponent<Trigger>();
}
// Update is called once per frame
void Update()
{
}
public void newObject(string Square)
{
GameObject Instance = Instantiate (Square, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
Instance.name = Square;
}
}
Assets\\script\\Produce.cs(10,24): 错误 CS1002: ; 预期 Assets\\script\\Produce.cs(10,23): 错误 CS1003: 语法错误, ',' 预期
我收到此错误 解决方法是什么?
您必须定义trigger
和square
,然后从编辑器(拖放)分配游戏对象。
[SerializeField] private GameObject square = null;
var trigger = square.AddComponent<Trigger>();
如果您不使用它,也删除函数Update()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.