Jump to content
Unity Insider Forum

Error CS0019


dieDoub
 Share

Recommended Posts

Hallo.

ich habe mir ein Video auf Youtube angesehen wegen das Lernen  vom Programmieren habe alles so eingegebn wie es gesasgt wurde doch nun kam die Fehlermeldung mit error CS0019.

operator "+" cannot be applied to operands of Type "Vector3" and "float"

ich habe alles probiert und durchsucht aber kein lösungsweg gefunden

Hier mein Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Playercontroller : MonoBehaviour
{
 
    public float walkingSpeed = 8.0f;
    public float runningSpeed = 12.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 18.0f;
    public Camera playerCamera;
    public float lookSpeed = 2.5f;
    public float lookXLimit = 45.0f;
 
    CharacterController characterController;
    Vector3 moveDirection = Vector3.zero;
    float rotationX = 0;
 
    [HideInInspector]
    public bool canMove = true;
 
    // Start is called before the first frame update
    void Start()
    {
       
        characterController = GetComponent<CharacterController>();
 
        //locking cursor
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
 
    }
 
    // Update is called once per frame
    void Update()
    {
       
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 right = transform.TransformDirection(Vector3.right);
 
        //Left Shift to Run
        bool isRunning = Input.GetKey(KeyCode.LeftShift);
        float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) *  Input.GetAxis("Vertical") : 0;
        float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) *  Input.GetAxis("Horizontal") : 0;
        float movementDirectionY = moveDirection.y;
        moveDirection = (forward + curSpeedX) + (right * curSpeedY);
 
        //Jumping
        if(Input.GetButton("Jump") && canMove && characterController.isGrounded)
        {      
                moveDirection.y = jumpSpeed;
        }
        else
        {
                moveDirection.y = movementDirectionY;
        }
       
 
        //Gravity
        if(!characterController.isGrounded)
        {
                moveDirection.y -= gravity * Time.deltaTime;
        }
 
        //Moving
        characterController.Move(moveDirection * Time.deltaTime);
 
        //Camera Rotation
        if(canMove)
        {
                rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
                rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
                playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
                transform.rotation *=Quaternion.Euler(0, Input.GetAxis("Mouse x") * lookSpeed, 0);
        }
    }
       
}
Link to comment
Share on other sites

Da im Bereich "Left Shift to Run" hast du in der Zeile für die MoveDirection ein Plus drin. Du willst da forward und curSpeedX addieren.

Geht, nicht! Die Fehlermeldung sollte dir auch genau diese Zeile im Script anzeigen.

Man kann nicht einen Vector, der aus 3 Werten besteht, mit einem anderen Wert addieren.
Multiplizieren geht aber, also mach aus dem Plus ein Mal.

Was anderes: Wieso hast du denn da so irre viel Platz zwischen den Zeilen? Da scrollt man sich ja einen Wolf!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...