Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jaidan · Mar 27, 2016 at 04:30 PM · c#vector3error message

Problem with Crouch Script - 3D C#

I cant seem to work out what the problem with my script is, here it is below:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(CharacterController))]
 public class FirstPersonController : MonoBehaviour {
 
     public float movementSpeed = 5.0f;
     public float mouseSensitivity = 5.0f;
     public float jumpSpeed = 20.0f;
 
     float verticalRotation = 0;
     public float upDownRange = 60.0f;
 
     float verticalVelocity = 0;
 
     CharacterController characterController;
 
     //Crouching
     private float crouchHeight;
     private float standardHeight;
     private bool crouching = false;
     private GameObject mainCamera;
 
     void Start () {
         //Cursor.lockState = CursorLockMode.Locked;
         characterController = GetComponent<CharacterController>();
         mainCamera = GameObject.FindGameObjectWithTag ("MainCamera");
         standardHeight = characterController.height;
         crouchHeight = (characterController.height / 2);
         crouching = false;
 
     }
         
     void Update () {
         float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
         transform.Rotate(0, rotLeftRight, 0);
 
 
         verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
         verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
         Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
 
         float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
         float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
 
         verticalVelocity += Physics.gravity.y * Time.deltaTime;
 
         if( characterController.isGrounded && Input.GetButton("Jump") ) {
             verticalVelocity = jumpSpeed;
         }
 
         Vector3 speed = new Vector3( sideSpeed, verticalVelocity, forwardSpeed );
 
         speed = transform.rotation * speed;
 
         characterController.Move( speed * Time.deltaTime );
 
         if (Input.GetKey (KeyCode.LeftShift)) {
             if (crouching) {
                 characterController.height = standardHeight;
                 characterController.center = new Vector3 (0, 0, 0);
                 mainCamera.transform.localPosition += Vector3(0, crouchHeight, 0);
                 crouching = false;
                 return;
             }
 
             if (!crouching) {
                 Crouch ();
             }
         }
     }
 
     void Crouch() {
         characterController.height = crouchHeight;
         characterController.center = new Vector3 (0, -0.5, 0);
         mainCamera.transform.localPosition.y -= Vector3(0, crouchHeight, 0);
         crouching = true;
     }
 }


Here are the errors that come up: Assets/FirstPersonController.cs(62,71): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

Assets/FirstPersonController.cs(75,70): error CS1502: The best overloaded method match for UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments Assets/FirstPersonController.cs(75,70): error CS1503: Argument #2' cannot convert double' expression to type float'

Assets/FirstPersonController.cs(76,57): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

If anyone could help, I would be very grateful :D

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zeoli · Mar 27, 2016 at 04:33 PM

On line 75, put an f after - 0.5 to denote a float otherwise it is a double. I. E. - 0.5f

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jaidan · Mar 27, 2016 at 04:40 PM

Thank you! , that sorted out two of the errors, I just have these two left:

Assets/FirstPersonController.cs(62,71): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

Assets/FirstPersonController.cs(76,57): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zeoli · Mar 27, 2016 at 05:01 PM 0
Share

These usually mean you have a type ins$$anonymous$$d of the variable you intend. Try creating a vector3 variable on the line before the ones refered to and pass them ins$$anonymous$$d of new vector3().

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I solve this error? 1 Answer

NullReferenceException 1 Answer

c# help with rotate and rotatearound 0 Answers

Need help getting randomly moving particles to head to the nearest of 4 coordinates. 1 Answer

My game script is fine but I'm still getting unexpected class error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges