简体   繁体   中英

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): error CS1002: ; expected Assets\\script\\Produce.cs(10,23): error CS1003: Syntax error, ',' expected

I get this error What is the workaround?

You have to define trigger and square and then assign the gameObject from editor (drag & drop).

[SerializeField] private GameObject square = null;

var trigger = square.AddComponent<Trigger>();

Also remove function Update() if you are not using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM