'I'm Making A Unity Game and Adding Controller Support so I'm making a variable to add my controls class but I get an error
I'm following a tutorial to add controller support to my game (This One) but when I save my script I get this error:
Assets\Scripts\PlayerMovement.cs(9,5): error CS0246: The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)
Some how it even worked in another Unity project!?
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
InputMaster controls;
public float Force = 2000f;
public float leftrightForce = 500f;
void Awake()
{
controls = new PlayerControls();
controls.Gameplay.Move_Left.performed += Left();
controls.Gameplay.Move_Right.performed += Right();
}
void FixedUpdate()
{
rb.AddForce(0, 0, Force * Time.deltaTime); //Makes Cube Go Vroom-Vroom
if (rb.position.y < -1.47)
{
FindObjectOfType<GameManager>().EndGame();
}
}
void Left()
{
rb.AddForce(leftrightForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
void Right()
{
rb.AddForce(-leftrightForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
void OnEnable()
{
controls.Gameplay.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
}
}
If you know how to help please help!
Solution 1:[1]
instead of using ranndom.choice, maybe use pop and shuffle:
list_ = ["apple", "orange", "banana"]
new_list= list_[:]
random.shuffle (new_list)
for i in range(3):
print(new_list.pop())
Solution 2:[2]
You can use random.sample with k=len(list_) to create a new list that has been shuffled:
>>> random.sample(list_, k=len(list_))
['banana', 'apple', 'orange']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tal Folkman |
| Solution 2 |
