using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerattack : MonoBehaviour
{
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Attack();
}
}
public float speed;
public void adjustment(Collider2D _main)
{
move pc = _main.GetComponent<move>();
speed = pc.moveSpeed;
}
private void Attack()
{
Vector2 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;//rad2deg==弧度制转角度制
transform.rotation = Quaternion.Euler(0, 0, rotZ);
transform.GetChild(0).gameObject.SetActive(true);
}
}
这个是本体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
public Rigidbody2D rb;
public float moveH, moveV;
public float moveSpeed=5f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Speed(moveH, moveV);
}
public void FixedUpdate()
{
rb.velocity = new Vector2(moveH, moveV);
}
public void Speed(float _moveH,float _moveV)
{
_moveH = new move().moveH;
_moveV = new move().moveV;
moveH = Input.GetAxis("Horizontal") * moveSpeed;
moveV = Input.GetAxis("Vertical") * moveSpeed;
if (moveH > 0)
transform.eulerAngles = new Vector3(0, 0, 0);
if (moveH < 0)
transform.eulerAngles = new Vector3(0, 180, 0);
}
}
这个是引用的函数的脚本
这个报错?