'Vector3' does not contain a definition for 'Input' error - c#

"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.

Related

The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?)

`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
[SerializeField]
public float speed = 3.5f;
// Start is called before the first frame update
void Start()
{
transform.position = new Vector(63, 15, 51);
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right *horizontalInput *speed * Time.deltaTime);
}
}
`
i tried googling the problem i found solutions but i am not making a typo , also 'Vector3' and Time.deltaTime wasnt being highlighted
The type or namespace name 'Vector' could not be found
the only vector i see, is
transform.position = new Vector(63, 15, 51);
maybe change it to:
transform.position = new Vector3(63, 15, 51);
the update function looks good, are you sure that the error occurs there?

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

ThirdPersonMovement script Unity

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

I have a bug in the renderer

public class Scroll : MonoBehaviour {
public float speed = 0.5f;
void Update()
{
Vector2 offset = new Vector2(0, Time.time * speed);
renderer.material.mainTextureOffset = offset;
}
i didn't understand where the problem is, but it is supposed to be in the renderer.material part.
I have put this code in a Quad to try and make it my background.
edit: error messages :
- Assets/Scroll.cs(12,8): error CS0619: UnityEngine.Component.renderer' is obsolete:Property renderer has been deprecated. Use GetComponent() instead. (UnityUpgradable)'
- Assets/Scroll.cs(12,17): error CS1061: Type UnityEngine.Component' does not contain a definition formaterial' and no extension method material' of typeUnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)
- nable to parse file Assets/Game scene.unity.meta: [Control characters are not allowed] at line 0
You can no longer access renderer that is inherited from MonoBehaviour directly. You must use GetComponent to get the Renderer. The-same thing applies to other components such as Rigidbody and AudioSource.
Renderer myRenderer;
public float speed = 0.5f;
void Start()
{
myRenderer = GetComponent<Renderer>();
}
// Update is called once per frame
void Update()
{
Vector2 offset = new Vector2(0, Time.time * speed);
myRenderer.material.mainTextureOffset = offset;
}
Of-course, GetComponent<Renderer>().material.mainTextureOffset = offset; could have worked too but it is better to cache it like I did in the first script.

Unity-trying to adjust brightness

using UnityEngine;
using System.Collections;
public class DayNight : MonoBehaviour{}
// Use this for initialization
void start (){
private float, smooth = 0.0000000000005;
}
// Update is called once per frame
void Update () {
IEnumerator IntensityChanging ()
{
float intensityA = 0.05f;
float intensityB = 5f;;
while( 1 == 1){
newIntensity = intensityA;
newIntensity = intensityB;
light.intensity = Math.Lerp(light.intensity, newIntensity, smooth * Time.deltaTime);
}
}
}
Errors
Assets/Scripts/DayNight.cs(7,15): error CS1525: Unexpected symbol private'
Assets/Scripts/DayNight.cs(6,14): error CS0116: A namespace can only contain types and namespace declarations
Assets/Scripts/DayNight.cs(13,39): error CS1525: Unexpected symbol(', expecting )',,', ;',[', or `='
Assets/Scripts/DayNight.cs(10,14): error CS0116: A namespace can only contain types and namespace declarations
Assets/Scripts/DayNight.cs(25,1): error CS8025: Parsing error
Thanks in advance.
All that code is just unusable, it seems a lot of copypaste's without no sense.
The most approximated I can think is:
using UnityEngine;
using System.Collections;
public class DayNight : MonoBehaviour{
private float smooth = 0.0000000000005;
// Use this for initialization
void start (){
}
float accumulate = 0;
// Update is called once per frame
void Update ()
{
float intensityA = 0.05f;
float intensityB = 5f;
accumulate += Time.deltaTime;
light.intensity = Math.Lerp(intensityA, intensityB, smooth * accumulate);
}
}
The only problem with that code is that light comes from nowhere, you need the reference to the light.

Categories