这是代码。当我尝试将脚本添加到Sprite时,出现“不允许主构造函数主体”错误。 在代码编辑器内部没有警报。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weapon : MonoBehaviour {
public GameObject dapo;
public float offset;
public Transform mira;
private float tiempo;
public float inicio;
private void Update()
{
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
if (tiempo <= 0)
{
if (Input.GetMouseButtonDown(0))
{
Instantiate(dapo, mira.position, transform.rotation);
tiempo = inicio;
}
}
else
{
tiempo -= Time.deltaTime;
}
}
}