ThirdPersonMovement script Unity - c#

I was following this video: https://youtu.be/4HpC--2iowE?t=686
And after making the thirdpersonmovement script, I get an error that he did not get. Can anyone help me? There's probably a very small error that I cannot see, I must be blind. I followed the exact steps.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 6f;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vetrical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
controller.Move(direction * speed * Time.deltaTime);
}
}
}
Error:
Assets\Scripts\ThirdPersonMovement.cs(16,57): error CS0103: The name 'Vertical' does not exist in the current context
Says error is on line 16. where "vector3 direction" is located
If the code is kinda wonky sorry, first time using this, was a weird set up for me.Thank you in advance.

There is a typo:
vetrical
vertical
t and r are swapped

Related

SceneManager does not contain a definition

Got a problem with using the scene manager. Already had a using UnityEngine.SceneManagement still shows the error of both LoadScene and GetActiveScene. I don't have a class such as "SceneManager". Here is the code.
using UnityEngine.SceneManagement;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
bool alive = true;
public float speed = 5f;
public Rigidbody rb;
float horizontalInput;
float horizontalMultiplier = 1.7f;
private void FixedUpdate()
{
if (!alive) return;
Vector3 forwardMove = transform.forward * speed * Time.fixedDeltaTime;
Vector3 horizontalMove = transform.right * horizontalInput * speed * Time.fixedDeltaTime * horizontalMultiplier;
rb.MovePosition(rb.position + forwardMove + horizontalMove);
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
if (transform.position.y < -5)
{
end();
}
}
public void end ()
{
alive = false;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Here is the error I have.
First of all try:
UnityEngine.SceneManagement.SceneManager.LoadScene( "myScene");
There can be 2 troubles:
First -
This happened to me. I had downloaded an asset off the store called Falling Leaves. It included a script called SceneManager. Namespaces should be better utilized for store assets. I'll have to take a look at the code to my own to make sure I'm not breaking someone else's project unintentionally.
Second - if you are wirtting kinda your own lib for unity check that all .dll / projects was imported or if you are writting code in folder that marked with .asmdef this is tool in unity that helps with faster compile and more separeted development (there) and if you are do smth with this asmdef file and checkbox "include unity engine" is not setted as true this is too can be reason so check pls
Same question was answered there https://forum.unity.com/threads/scenemanager-does-not-contain-a-definition-for-loadscene.388892/
I believe you have to be using UnityEngine; before actually using UnityEngine.SceneManagement
here's an example
using UnityEngine; using UnityEngine.SceneManagement;
the problem here is that your using a part or branch or something of EnityEngine before using UnityEngine itself

C# Pong Game - problem with ball scripting

I was just copying a tutorial on YouTube on how to make the pong game and when it came to scripting the ball, there was an error for me but not the guy in the video.
I have no experience in C#, only Python. This is the error message:
Assets\Ball.cs(24,26): error CS0117: 'Random' does not contain a definition for 'range'
Anyone know what's wrong?
This is the script for it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
public float speed;
public Rigidbody2D rb;
//Start is called before the first frame update
void Start()
{
Launch();
}
//Update is called once per frame
void Update()
{
}
private void Launch()
{
float x = Random.range(0,2) == 0 ? -1 : 1;
float y = Random.range(0,2) == 0 ? -1 : 1;
rb.velocity = new Vector2(speed * x, speed * y);
}
}
You have to write Random.Range and not Random.range
You need to capitalize "range", Random.Range is a method and most methods start with a capital letter so instead of "Random.range", you need to type "Random.Range"
Here the script method just calls the "Launch()" method at initialization time, your "Lauch()" method is problematic, you can try to modify the "Random.range(0,2)" method to "Random.Range(0, 2)"

Can someone help me fix this jumpscript?

Im trying to make my character jump in unity2D,the jump itself works but i cant properly check if my player touches the ground.
I get 2 errors in the unity console.
the first one :
Physics2D does not contain a defenition for OverLapArea.
the second error :
Vector2 does not contain a constructor that takes 3 arguments.
(also i apologise for my bad english,its not my native language)
The script :
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class jump : MonoBehaviour
{
public bool IsGrounded;
public LayerMask platfomLayer;
public Rigidbody2D rb2D ;
// Start is called before the first frame update
void Start()
{
rb2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
IsGrounded = Physics2D.OverLapArea (new Vector2(transform.position.x - 0.5f, transform.position.x - 0.5f),
new Vector2(transform.position.x + 0.5f, transform.position.y - 0, 51f),platfomLayer);
{
if (Input.GetKeyDown("space") && IsGrounded) rb2D.AddForce(transform.up * 2000f);
}
}
}
The errors are both correct.
OverLapArea is spelled correctly but capitalized wrong. Unity references are case-sensitive.
You are indeed trying to pass 3 values into a new Vector2. Look carefully at what you're passing into your second new Vector2 value. You have three values separated by commas within the parenthesis. It looks like you mis-typed "0.5f" as "0, 51f"

input axis vertical is not set up (C#) in Unity

I'm trying to implement a player movement script but whenever I run the project it just displays the error "ArgumentException: Input Axis Verticle is not setup. To change the input settings use: Edit -> Settings -> Input PlayerMovement.Update () (at Assets/PlayerMovement.cs:14)"
I tried going into input controls and 'setting up the verticle axis' but to be honest I have no clue how. Also, I'm not sure is it is supposed to be like this, but when I change the verticle axis in the input settings to the y-axis it automatically changes the horizontal-axis to 'y' as well. here is my code in case it is needed but it did not display any errors
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Verticle");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
}
}
also, I am using C# in Unity.
Thanks in advance!
B.G
float z = Input.GetAxis("Verticle");
change to
float z = Input.GetAxis("Vertical");
detailed instructions on changing input in future : https://docs.unity3d.com/Manual/class-InputManager.html

'Vector3' does not contain a definition for 'Input' error

"Assets/MovePlayer.cs(27,70): error CS1061: 'Vector3' does not contain a definition for 'Input' and no accessible extension method 'Input' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?)"
I am making a small game, I've been trying to add camera relative movements and it keeps showing me the error above.
Here is my code for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
public Transform cam;
Vector2 input;
void Update()
{
input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
input = Vector2.ClampMagnitude(input,1);
Vector3 camF = cam.forward;
Vector3 camR = cam.right;
camF.y = 0;
camR.y= 0;
camF = camF.normalized;
camR = camR.normalized;
transform.position += (camF*input.y + camR.input.x)*Time.deltaTime*5;
}
}
I've also added a CameraLook component to my Main Camera, if you would like to look at that as well.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraLook : MonoBehaviour {
Vector2 rotation = new Vector2 (0, 0);
public float speed = 3;
void Update () {
rotation.y += Input.GetAxis ("Mouse X");
rotation.x += -Input.GetAxis ("Mouse Y");
transform.eulerAngles = (Vector2)rotation * speed;
}
}
This likely needs to be transform.position += (camF*input.y + camR * input.x)*Time.deltaTime*5;
You're trying to access camR.input which isn't a property of camR which is a Vector3. I think you're intending to multiply camF by input.x instead.
FYI, You can double click on the error message in visual studio, or monodevelop and it will take you to the error line.
You have camR.input.x, which means it's trying to access a member of camR (which is a Vector3) called input, which doesn't exist.
You meant to write camR * input.x.

Categories