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 1 year ago.
Improve this question
so I have been following this tutorial to create a leaderboard system. Link below
https://www.youtube.com/watch?v=x0Wy7jQ7EFU&t=207s&ab_channel=EEDev
but I had problem on this following script
public class ScoreData : MonoBehaviour
{
public List<Score> scores;
public ScoreData()
{
scores = new List<Score>();
}
}
the console said
"You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()"
the tutorial had no problem running but mine has. Hope to have some insight on the matter.
you need to remove : MonoBehaviour from the class Score
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I tried to fix it on youtube and it didn't work
Move line 8 up to line 6. It should look like:
public class move : MonoBehaviour {
public float dichuyen;
public float tocdo;
void Start() {}
..
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
I.e, does the abstract modifier do anything here:
public abstract class MyClass<T> where T : class {
}
You can't use Generic classes on their own anyway, so what difference does it make if it's abstract or not?
With the abstract keyword, you have to subclass it to use it.
class MySubclass : MyClass<string>
{
}
var o = new MySubclass();
Without it, you can instantiate directly:
var o = new MyClass<string>();
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 5 years ago.
Improve this question
I want my little cube to change to a bigger one when i click the upper arrow, and change back when i pres the down arrow. I have tried:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSkift : MonoBehaviour {
public gameObject myObject1;
public gameObject myObject2;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.UpArrow))
{
myObject1.SetActive (false);
myObject2.SetActive (true);
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
myObject2.SetActive(false);
myObject1.SetActive(true);
}
}
}
When i try to run it it says:
Assets/PlayerSkift.cs(9,9): error CS0118: `UnityEngine.Component.gameObject' is a `property' but a `type' was expected
I have no idea what that means, so if you know it, or know how to do it in a other way. Please help.
public gameObject myObject1;
public gameObject myObject2;
the above code, as per this discussion, appears to have a typo.
gameObject should be GameObject.
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 5 years ago.
Improve this question
I'm trying to turn off the gravity for one instantiated prefab clone, if something in the game happens. I have this:
public class Controller : MonoBehaviour
public Transform randomcoin;
private void Start()
if ( ... )
{ randomcoin.GetComponent<Rigidbody>.useGravity = false; }
This gives me this error:
Component.GetComponent<T>() is a method, which is not valid in the given context
Does anyone know how I can fix this?
You're missing () in randomcoin.GetComponent<Rigidbody>
It should be like this:
randomcoin.GetComponent<Rigidbody>()
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
Every time I'd put in static it would keep replacing it with ContextStaticAttribute.
I need 10 rep to post images, but here's the link: http://i.imgur.com/jBOOF3s.png)
I also do not want to have to press the right arrow to put in a local variable!
I just figured out how you did this by typing static inside a method.
Variables in a method cannot be static, only class level elements can.
Simply declare those variables inside the class, not a method.
Example:
namespace ConsoleApplication2
{
class Program
{
static string username; // Correct
private static void Main()
{
static // Incorrect
}
}
}