How can I solve this issue in C# Unity [closed] - c#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Here is my function:
public void PowerupCollected(int AddScore)
{
score += AddScore;
scoreGUI.text = "lol"+score;
}
Here is how I call that function:
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected();
}
here is the error message
error CS1501: No overload for method `PowerupCollected' takes 0 arguments
What is wrong? Is it because I don't include AddScore when in brackets when I call the function?

Either add the AddScore argument to your call (say control.PowerupCollected(42); or make the argument optional: public void PowerupCollected(int AddScore = 0).
Since second solution doesn't make sense in your case, i'd use first one.

Your function call should include the amount of score you want to add:
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected();
}
should be (for example):
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected(10);
}
This would add 10 to your score.

Related

Does any one know what is the problem here? The error is: Type or namespace definition, or end-of-file expected [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playershoot : MonoBehaviour
{
public static Action shootInput;
private void Update()
{
if (Input.GetMouseButton(0))
}
{
shootInput?.Invoke();
}
}
I watched a tutorial from youtube (I'm a new programmer to c#) and did exactly what I was told to but that happened.
Your Method is not properly closing the scope. Your if statement falls half outsite the method closing bracket so you have statements in places where they cant legally be placed
private void Update()
{
if (Input.GetMouseButton(0))
}
{ //here
shootInput?.Invoke();
} // here
it should be as below where the if statement is enclosed within the method definition
private void Update()
{
if (Input.GetMouseButton(0))
{
shootInput?.Invoke();
}
}

Awaiting code inside of anonymous function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
So I have some code that I need to execute when an form activates its Shown event, and I need to await that code. I am doing this:
form.Shown += async (sender, args) => await BufferOpen(CurrentPath, CurrentEncoding, 1024 * 1024 * 5, statusProgressForm.progressBar1);
statusProgressForm.Show();
But the code still continues without awaiting the BufferOpen method. How can I do this with an anonymous function?
EDIT:
Ok, so I think I screwed up the original post. Sorry about that. What I'm really trying to do is show a form and THEN on the shown event perform intensive code, as before when I just did this:
form.Show();
DoIntensiveTasks();
The GUI on the form would not properly load and the labels and such wouldn't display properly. I need to wait until the form is completely shown then do stuff.
The problem is that because you used an expression lambda it's only performing the one expression as a part of that anonymous method, and thus the Show call isn't a part of that anonymous method. All it takes is to use brackets to make it a statement lambda:
form.Shown += async (sender, args) =>
{
await BufferOpen(CurrentPath, CurrentEncoding, 1024 * 1024 * 5, statusProgressForm.progressBar1);
statusProgressForm.Show();
};

Unity3d "Cannot implicitly convert type `void' to `bool'" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
void Update ()
{
if (transform.Translate((Input.acceleration.x), 0, 0))
{
GetComponent<Rigidbody>().AddForce(Vector2.right);
}
}
I am using the accelerator for a Android App and doesn't seem to like it. I can change it to work for KeyDown but it wont work with the accelerator.
Error:
"Cannot implicitly convert type "void" to "bool"
According to the documentation http://docs.unity3d.com/ScriptReference/Transform.Translate.html:
transform.Translate does not return a boolean; its return type is void. Therefore you cannot use an if statement to evaluate whether or not it was successful.
If you want to check to see if the translate happened correctly you would need to check the side effects from calling transform.Translate. In other words see what has changed on the transform and see if it matches your expectations.
Don't use the if statement, as Translate returns nothing. Just leave the AddForce line

Passing List into method [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Simple question I think. I am trying to pass in a list that I created within my Main into a method. I am missing something but can't quite put my finger on it.
Declaration
List<string> emulationList = new List<string>();
Method Call
sataHeader = ParseSataHeader(sataHeader, bcuFileName, List<string> emulationList);
Method Implementation
private static string ParseSataHeader(string sataHeader, string bcuFileName, List<string> emulationList)
{
//some code
}
You don't specify the type when passing arguments.
Change your second snippet to:
sataHeader = ParseSataHeader(sataHeader, bcuFileName, emulationList);
And it will work just fine.

Use of unassigned local variable 'TargetControl' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Showing error in line 3.
Code in Below
if (this.Page.Master != null)
{
Control TargetControl;
if (this.Page.Master.FindControl(this.TargetControlID) != null)
{
return this.Page.Master.FindControl(this.TargetControlID);
}
return TargetControl;
}
Change your code to just this:
return Page.Master.FindControl(TargetControlID);
This will either return null if its not found or it'll return the control.
Use of unassigned local variable 'TargetControl'
Your error is because you're declaring a variable here:
Control TargetControl;
But never assigning it a value. You must assign values to variables before using them.
The quick solution is this:
Control TargetControl = null;
..but then, that is pretty useless in itself, you can just do this:
return this.Page.Master.FindControl(this.TargetControlID);

Categories

Resources