I'm currently following a tutorial about game dev on Unity (by Natty Creations) and I'm getting an error which I cannot solve (sorry I'm very new to this and I don't know how things work). the error is
Assets/Scripts/InputManager.cs(23,34): error CS1061:
'PlayerInput.OnFootActions' does not contain a definition for
'Movement' and no accessible extension method 'Movement' accepting a
first argument of type 'PlayerInput.OnFootActions' could be found (are
you missing a using directive or an assembly reference?)
I get this same error for three elements in my code, which is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
private PlayerInput playerInput;
private PlayerInput.OnFootActions onFoot;
private PlayerMotor motor;
// Start is called before the first frame update
void Awake()
{
playerInput = new PlayerInput();
onFoot = playerInput.OnFoot;
motor = GetComponent<PlayerMotor>();
}
// Update is called once per frame
void FixedUpdate()
{
//tell the player motor to move using the value from our movement action
motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
}
private void OnEnable()
{
onFoot.Enable();
}
private void OnDisable()
{
onFoot.Disable();
}
}
Does anyone have any idea on how to solve this? Thank you in advance, please be patient as I don't have much experience! ^_^
I followed the tutorial step by step but I still get problems :(
Related
I have a problem that when i change scenes from the menu to the game and when i click i will get the error 'The object of type 'GameObject' has been destroyed but you are still trying to access it.' and this is happening while the menucontroller is not in the game scene, i have been working on this for the past few days to fix it but cant find how to do it. If anyone can help that would be great this kind of question has been asked alot but I cant find a solution for my problem.
We also have a similar script that has the same code except instead of sceneswitching its for interaction so when we try to interact with something we get the error
Thank you for your help.
menucontroller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using API;
public class MenuController : MonoBehaviour
{
[SerializeField] private InputActionReference shoot;
[SerializeField] private InputActionReference shoot2;
public GameObject sendObject;
public GameObject sendObject2;
public float range = 1000;
void Start()
{
shoot.action.performed += Shoot;
}
async void Shoot(InputAction.CallbackContext obj)
{
RaycastHit hit;
if (Physics.Raycast(sendObject.transform.position, sendObject.transform.forward, out hit, range))
{
SceneManager.LoadScene("SampleScene");
}
}
}
The error message sounds quite self-explanatory.
You are trying to access an object that already was destroyed.
Since you load a new scene
SceneManager.LoadScene("SampleScene");
the current scene and its objects are unloaded / destroyed.
Whenever you deal with events
void Start()
{
shoot.action.performed += Shoot;
}
make sure to also remove the callback as soon as not needed/valid anymore
private void OnDestroy()
{
shoot.action.performed -= Shoot;
}
Im trying to make a Vuforia Video Player with virtual buttons but when I try to pause and play it gives me and error. I looked at some forums and some question that is old but they didnt fix my problem. Error is:
Assets\vp_time.cs(23,9): error CS0120: An object reference is required for the non-static field, method, or property 'VideoPlayer.Pause()'
Assets\vp_time.cs(27,9): error CS0120: An object reference is required for the non-static field, method, or property 'VideoPlayer.Play()'
Code is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using Vuforia;
public class vp_time : MonoBehaviour
{
public GameObject vbBtnObj;
public GameObject vbVpObj;
// Start is called before the first frame update
void Start()
{
vbBtnObj = GameObject.Find("VideoBtn");
vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed);
vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonReleased(OnButtonReleased);
vbVpObj.GetComponent<VideoPlayer>();
}
public void OnButtonPressed(VirtualButtonBehaviour vb){
VideoPlayer.Pause();
}
public void OnButtonReleased(VirtualButtonBehaviour vb){
VideoPlayer.Play();
}
// Update is called once per frame
void Update()
{
}
}
Well as the error says VideoPlayer is a type. It has no static method VideoPlayer.Play. You need a reference to an instance of type VideoPlayer and call the method on that instance.
vbVpObj.GetComponent<VideoPlayer>();
this line does absolutely nothing!
You rather wanted to store this reference in a field
// Drag this already in via the Inspector in Unity
[SerializeField] private VideoPlayer videoPlayer;
or do
private void Start ()
{
...
// As fallback get the reference on runtime ONCE
if(!videoPlayer) videoPlayer = vbVpObj.GetComponent<VideoPlayer>();
}
and later
videoPlayer.Play();
and
videoPlayer.Pause();
I am getting the following error trying to build an editor window in Unity 2019.3.14f:
Assets\Editor\CellViewer.cs(19,40): error CS0117: 'Selection' does not contain a definition for 'activeGameObject'
I have found evidence of a single person with this specific error on the unity answer board, but there are no answers or updates in 5 years. I have reloaded the project, restarted unity, and restarted my system multiple times since this error first appeared.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class CellViewer : EditorWindow
{
private Map map;
[MenuItem ("Window/Cell Viewer")]
public static void ShowWindow() {
EditorWindow.GetWindow(typeof(CellViewer));
}
void OnGUI () {
if(Map.isInstanceActive())
{
GameObject obj = Selection.activeGameObject;
Tile tile = obj.GetComponent<Tile>();
if(tile != null) {
map = Map.Instance();
loadCell(map.getCell(tile.coordinates)));
}
}
}
}
How could this have happened, and what can I do about it?
This can happen if the classname Selection is ambiguous because you've created a class by that name in the global namespace.
To make sure you're using the correct one you can have your code be explicit by adding:
GameObject obj = UnityEditor.Selection.activeGameObject
When using a script to hide and unhide specific sprites on the click of a button, I get these two errors.
Assets\Scripts\ButtonLeft.cs(26,5): error CS1061: 'int' does not contain a definition for 'SetActive' and no accessible extension method 'SetActive' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\ButtonLeft.cs(22,8): error CS1061: 'int' does not contain a definition for 'activeSelf' and no accessible extension method 'activeSelf' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
I was assured by previous posts, some only dating back a few weeks, that activeSelf was the correct way to check whether a sprite was already hidden, and I have used SetActive before in this project with no issues. Here's the script I'm trying to run:
using System.Collections.Generic;
using UnityEngine;
public class ButtonLeft : MonoBehaviour
{
public void Click ()
{
if (23.activeSelf)
{
23.SetActive (false);
3.SetActive (true);
1.SetActive (false);
}
if (3.activeSelf)
{
23.SetActive (false);
3.SetActive (false);
1.SetActive (true);
}
if (1.activeSelf)
{
23.SetActive (true);
3.SetActive (false);
1.SetActive (false);
}
}
// Update is called once per frame
void Update()
{
}
}
Is the syntax wrong in any way? Is activeSelf not the correct way to check whether an object is active or not?
Using Unity 2019.4.5f1 Personal
The reason you're getting those error messages is due to running them on integers instead of sprites. You need to use an instance of a GameObject.
You can acquire a reference to something of that sort in several ways. One would be by making a field that's exposed to the inspector and providing the reference through there.
using UnityEngine;
public class ButtonLeft : MonoBehaviour
{
[SerializeField]
private SpriteRenderer sprite1 = null;
[SerializeField]
private SpriteRenderer sprite3 = null;
[SerializeField]
private SpriteRenderer sprite23 = null;
public void Click()
{
if (sprite23.gameObject.activeSelf)
{
sprite23.gameObject.SetActive(false);
sprite3.gameObject.SetActive(true);
sprite1.gameObject.SetActive(false);
}
if (sprite3.gameObject.activeSelf)
{
sprite23.gameObject.SetActive(false);
sprite3.gameObject.SetActive(false);
sprite1.gameObject.SetActive(true);
}
if (sprite1.gameObject.activeSelf)
{
sprite23.gameObject.SetActive(true);
sprite3.gameObject.SetActive(false);
sprite1.gameObject.SetActive(false);
}
}
}
How things may end up looking in the editor:
If you want to be able to drag in any game object as a reference
using UnityEngine;
public class ButtonLeft : MonoBehaviour
{
[SerializeField]
private GameObject sprite1 = null;
[SerializeField]
private GameObject sprite3 = null;
[SerializeField]
private GameObject sprite23 = null;
public void Click()
{
if (sprite23.activeSelf)
{
sprite23.SetActive(false);
sprite3.SetActive(true);
sprite1.SetActive(false);
}
if (sprite3.activeSelf)
{
sprite23.SetActive(false);
sprite3.SetActive(false);
sprite1.SetActive(true);
}
if (sprite1.activeSelf)
{
sprite23.SetActive(true);
sprite3.SetActive(false);
sprite1.SetActive(false);
}
}
}
Heyy I am learning Unity developpemnt engine , but when I try associate my script to my sprite I got this error : Unity Error CS0103 : the name 'input' does not exist in the current context , my code is very simlpe ,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playermovement : MonoBehaviour {
public float speed;
private Rigidbody2D myRigidbody;
private Vector2 change;
void Start() {
myRigidbody = GetComponent<Rigidbody2D>();
}
void Update() {
change = Vector2.zero;
change.x = Input.GetAxis("Horizontal");
change.y = input.GetAxis("Vertical");
Debug.Log(change);
}
}
So did somebody has the answer to my question ? I would accept any help thanks !
I am using ItelliJ IDEA to edit my C# scripts and Unity 2019.3.8f1 personnal
Cause you use input, instead of Input!
Care with capital letters!