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)'
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
CodePudding user response:
If you declare a method to take 1 parameter:
private void CambioDireccion(Collision collision)
^^^^^^^^^^^^^^^^^^^
1 parameter, of type Collision
You have to provide 1 argument (value for the parameter) when you call it. You cannot call it with 0 arguments like you have done:
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:
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 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):
CambioDireccion(variableThatIsACollision);
CambioDireccion(MethodThatReturnsACollision());
CambioDireccion(new Collision());
CambioDireccion(new Collision() { Prop1 = Value1, Prop2 = Value2 });
CodePudding user response:
Just remove "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. So basicly you want to wait for CollisionEnter message and then check tag and change direction. (Press Ctrl Shift M in VS to see all available messages)