【发布时间】:2021-08-07 07:54:35
【问题描述】:
所以我创建了一个脚本,该脚本将根据按下到特定 x,y 位置的键来实例化不同的预制件。现在我想编辑它,而不是在特定点内生成,而是在 x1,x2 , y1,y2 区域内随机生成预制件。
这是我现在使用的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Instantiator : MonoBehaviour
{
//Instantiator for Left
public KeyCode keyToPress;
public GameObject[] FI;
public GameObject clone;
// Update cause update is cooler
void Update()
{
var transform.positionA = Vector2(Random.Range(-12, -10), Random.Range(-1, 1));
var transform.positionD = Vector2(Random.Range(12, 10), Random.Range(-1, 1));
var transform.positionS = Vector2(Random.Range(-1, 1), Random.Range(-6, -5));
var transform.positionW = Vector2(Random.Range(-1, 1), Random.Range(6, 5));
if (Input.GetKeyDown(KeyCode.A))
{
clone = Instantiate(FI[0], positionA, Quaternion.identity);
}
else if (Input.GetKeyDown(KeyCode.D))
{
clone = Instantiate(FI[1], positionD, Quaternion.identity);
}
else if (Input.GetKeyDown(KeyCode.S))
{
clone = Instantiate(FI[2], positionS, Quaternion.identity);
}
else if (Input.GetKeyDown(KeyCode.W))
{
clone = Instantiate(FI[3], positionW, Quaternion.identity);
}
}
}
但是,我收到语法错误 ["," expected 和 ";"预计]
【问题讨论】:
标签: c# unity3d compiler-errors