[英]Unity Error CS7036: No argument given that corresponds to the required formal parameter
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OblstacleMove : MonoBehaviour
{
public GameObject Obstacle;
public int velocidad;
private int VelocidadRotacion;
public
// Start is called before the first frame update
void Start()
{
velocidad = 3;
}
// Update is called once per frame
void Update()
{
if (gameObject.tag == "Vertical")
{
Obstacle.transform.Rotate(1, 0, 0, Space.Self);
}
if (gameObject.tag == "Horizontal")
{
Obstacle.transform.Rotate(0, 0, 1, Space.Self);
}
if(gameObject.tag == "Cube")
{
transform.Translate(new Vector2(velocidad * Time.deltaTime, 0));
ChangeDirection();
}
//Obstacle.transform.Rotate(0, 0, 1, Space.Self);
}
public void ChangeDirection(Collision collision)
{
if(collision.gameObject.tag == "MapLimit")
{
velocidad = velocidad * -1;
}
}
}
i get this error:我收到此错误:
Assets\Scripts\OblstacleMove.cs(30,13): error CS7036: There is no argument given that corresponds to the required formal parameter 'collision' of 'OblstacleMove.CambioDireccion(Collision)' Assets\Scripts\OblstacleMove.cs(30,13):错误 CS7036:没有给定的参数对应于“OblstacleMove.CambioDireccion(Collision)”所需的形式参数“collision”
i tryed我试过了
if(gameObject.tag == "Cube")
{
transform.Translate(new Vector2(velocidad * Time.deltaTime, 0));
CambioDireccion(Collision collision);
}
and it didnt work, i also tryed它没有用,我也试过了
private void ChangeDirection(Collision collision)
{
if(collision.gameObject.tag == "MapLimit")
{
velocidad = velocidad * -1;
}
}
i dont know what else to try我不知道还能尝试什么
If you declare a method to take 1 parameter:如果你声明一个方法接受 1 个参数:
private void CambioDireccion(Collision collision)
^^^^^^^^^^^^^^^^^^^
1 parameter, of type Collision
You have to provide 1 argument (value for the parameter) when you call it.调用它时必须提供 1 个参数(参数值)。 You cannot call it with 0 arguments like you have done:
你不能像你所做的那样用 0 arguments 调用它:
CambioDireccion();
^^
0 arguments provided
Either provide 1 argument when you call it, or modify the method to accept 0 parameters, or change the parameter to be optional so it can be called with either 0 or 1 arguments:在调用它时提供 1 个参数,或者修改方法以接受 0 个参数,或者将参数更改为可选参数,以便可以使用 0 或 1 arguments 调用它:
CambioDireccion(...); //calling the method providing an argument. Replace ... with some relevant instance of a Collision object. This is the most likely resolution
private void CambioDireccion(){ //modify the method to accept 0 parameters. This will likely fail because the method body uses the passed-in argument
private void CambioDireccion(Collision collision = ...) //modify the method so the parameter is optional; provide a sensible default in place of `...`. Often this is `null`. The method body would have to be modified in some way to work for the case where the optional element was leveraged; perhaps checking for null and responding differently
You have to decide what the most logical course of action is from these options.您必须从这些选项中决定最合乎逻辑的行动方案。 It's probably going to be to provide a Collision object, something like:
它可能会提供一个 Collision object,类似于:
Collision c = ... //get a Collision from somewhere or make one
CambioDireccion(c);
When you call a method and provide arguments, you dont specify the type, just the name of the variable that is the type, or the name of a method that returns an instance of the type, or a call to make a new one of the type (which may include property initializers):当你调用一个方法并提供 arguments 时,你没有指定类型,只是指定类型变量的名称,或者返回类型实例的方法的名称,或者调用一个新的类型(可能包括属性初始值设定项):
CambioDireccion(variableThatIsACollision);
CambioDireccion(MethodThatReturnsACollision());
CambioDireccion(new Collision());
CambioDireccion(new Collision() { Prop1 = Value1, Prop2 = Value2 });
Just remove "ChangeDirection();"只需删除“ChangeDirection();” from Update and change its name to "OnCollisionEnter", these names are important because these are Unity Messages that are being invoked when certain things in game happen.
从 Update 并将其名称更改为“OnCollisionEnter”,这些名称很重要,因为这些是在游戏中发生某些事情时调用的 Unity 消息。 So basicly you want to wait for CollisionEnter message and then check tag and change direction.
所以基本上你想等待 CollisionEnter 消息,然后检查标签并改变方向。 (Press Ctrl + Shift + M in VS to see all available messages)
(在 VS 中按 Ctrl + Shift + M 可查看所有可用消息)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.