Your method that your testing must return a boolean for the operator to work.
The error is suggesting that you’re attempting to operate it on a ‘method group’ (the name of a function, rather than the return… a function must be followed by parens to get its return), and a ‘void’. In the case of the ‘void’, that’s a method that you called, but it has no return value.
public void up()
{
//...
}
This method does not return anything, hence the ‘void’.
You can’t operate a boolean operator on method groups and voids…
Fixing it requires that the functions returns you’re comparing return true/false.
Of course, since your existing ‘Update’ code is already testing for these keypresses, those are going to ALSO move it up. So you might want to remove that stuff as well.
using UnityEngine;
using System.Collections;
public class player_controller : MonoBehaviour
{
// public Vector3 movement ==
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
transform.position += Vector3.up;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
transform.position += Vector3.down;
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.position += Vector3.left;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.position += Vector3.right;
}
}
public bool up()
{
transform.position += Vector3.up;
return true;
}
public bool down()
{
transform.position += Vector3.down;
return true;
}
public bool left()
{
transform.position += Vector3.left;
return true;
}
public bool right()
{
transform.position += Vector3.right;
return true;
}
public bool isUnder()
{
const float distanceUp = 1;
return Physics.Raycast(transform.position, this.transform.up, distanceUp);
}
}
using UnityEngine;
using System.Collections;
public class push_logic : MonoBehaviour
{
public player_controller p;
// Use this for initialization
void Start()
{
p = GetComponent<player_controller>();
if ((p.isUnder()) && Input.GetKeyDown(KeyCode.UpArrow))
{
p.up();
}
}
// Update is called once per frame
void Update()
{
}
}
OK… lets forget all this code that you have for now. And try to rebuild from the ground up.
You say you want:
So from context I assume that “pushing the button to move” is pushing any of the arrow keys. And you want to move that relative to direction. So we need to be testing for each arrow key for a respective direction.
Furthermore, you only want this to happen if “I am under it”.
But is there anything for the raycast to hit? Does the ‘it’ have a collider on it or something?
Furthermore, your code here:
p = GetComponent<player_controller>();
implies that the player_controller and push_logic scripts are both on the same object. Again where is the ‘it’? How are we pushing that? All your logic as it stands deals with what appears to be the ‘player’.
Is there anything else that should be going on as well? Is the ‘i’… the ‘player’ supposed to ALSO be able to move?