command-line-api
command-line-api copied to clipboard
SetHandler error cannot convert from 'method group' to 'Action<FooStruct?>'
Seems like SetHandler cannot bind Option<A?>? with Handler(A a) when A is struct.
Please find the minimal sample over here, which has the exact code for a class and a struct where it is working for the class and failing for the struct with
error CS1503: Argument 2: cannot convert from 'method group' to 'Action<FooStruct?>'
As a workaround I can return an object? that I can cast back to a FooStruct. This, obviously, is not a solution and far from being optimal.
yo anyone wanna help me out? Ive got this problem on Unity where its telling me that it cannot covert method group "GetMouseButtonDown". On my project I made a gun and im trying to make it so that when you press the left mouse button it shoots. All my other code is already finished but this is my last obstacle, can anyone help?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Gun : MonoBehaviour { public Transform bulletPoint; public GameObject bulletPrefab; public float bulletspeed = 10;
void Update()
{
if (Input.GetMouseButtonDown)
{
var bullet = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation);
bullet.GetComponent<Rigidbody>().velocity = bulletPoint.forward * bulletspeed;
}
}
yo anyone wanna help me out? Ive got this problem on Unity where its telling me that it cannot covert method group "GetMouseButtonDown". On my project I made a gun and im trying to make it so that when you press the left mouse button it shoots. All my other code is already finished but this is my last obstacle, can anyone help?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Gun : MonoBehaviour { public Transform bulletPoint; public GameObject bulletPrefab; public float bulletspeed = 10;
void Update() { if (Input.GetMouseButtonDown) { var bullet = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation); bullet.GetComponent<Rigidbody>().velocity = bulletPoint.forward * bulletspeed; } }
Wrong repo for this question, but I think this is your answer.
Change:
if (Input.GetMouseButtonDown)
To:
if (Input.GetMouseButtonDown(0))
GetMouseButtonDown isn't a field or property, it is a method that takes an int (the button you're interested in) and returns a bool.
Is the issue clear @adamsitnik ? I fear due to the hijacking above that the intention of this case got lost. To remind back to the reported issue: I cannot bind Option<A?>? when A is a struct. A class, however, is supported.
Kind regards Dave