Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by 10chaos1 · Nov 11, 2014 at 04:42 AM · c#charactermotor

why is the charactermotor script not being recognised in this script

i was follwing a touorial on making the player swim under water and whilst doing so i found out that calling the character motor script is impossible why is this here is the script

 using UnityEngine;
 using System.Collections;
 
 public class Swim : MonoBehaviour {
 public CharacterController cc;
 public charatermotor cm;
 
     void Start ()
     {
     
     RenderSettings.fog = false;
     RenderSettings.fogColor = new Color(0.0f,0.8f,0.8f,0.5f);
     RenderSettings.fogDensity = 0.4f;
     
     }
     
     bool underwater(){
     
         return gameObject.transform.position.y < 58;
     }
     
         cc = GameObject.GetComponent <CharacterController>();
         cm = GameObject.GetComponent <CharacterMotor>();
     }
     
     void Update () 
     {
     RenderSettings.fog = underwater();
     
     if (underwater){
     
     cm.movement.MaxforwardSpeed = 2;
     cm.Movement.MaxSidewaysSpeed = 2;
     cm.Movement.MaxBackwardsSpeed = 2;
     cm.Movement.MaxFallSpeed = 2;
     
     //if (Input.GetKey(keycode.Space))
     
     }
     else
     {
         cm.movement.MaxforwardSpeed = 6;
         cm.Movement.MaxSidewaysSpeed = 6;
         cm.Movement.MaxBackwardsSpeed = 6;
         cm.Movement.MaxFallSpeed = 20;
         
     }
 
 }

i havent got around to adding the conditions for the input yet so i commented it out

as i said heres the pic confirming that the charactermotor script is active

and heres confiming that its the script was added as a part of the character controller package

confirm.png (156.3 kB)
confirm 2.png (29.6 kB)
Comment
Add comment · Show 1
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 10chaos1 · Nov 11, 2014 at 04:28 AM 0
Share

ive gone through and made the changes you suggested but there's still the problem of charactermotor not being seen its on the first person controller and active but he script cant see it ill update the question to include a screen shot of my project whitch shows that its active

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Nov 11, 2014 at 04:43 AM

Your script has many spelling and case issues. You need to be very careful that variables and class names match exactly. Here is a version of your script that compiles for me.

 using UnityEngine;
 using System.Collections;
 
 public class Swim : MonoBehaviour {
     public CharacterController cc;
     public CharacterMotor cm;
     
     void Start ()
     {
         RenderSettings.fog = false;
         RenderSettings.fogColor = new Color(0.0f,0.8f,0.8f,0.5f);
         RenderSettings.fogDensity = 0.4f;
         cc = gameObject.GetComponent <CharacterController>();
         cm = gameObject.GetComponent <CharacterMotor>();
     }
     
     bool Underwater(){
         return transform.position.y < 58;
     }
 
     void Update () 
     {
         RenderSettings.fog = Underwater();
         
         if (Underwater()) {
             
             cm.movement.maxForwardSpeed = 2;
             cm.movement.maxSidewaysSpeed = 2;
             cm.movement.maxBackwardsSpeed = 2;
             cm.movement.maxFallSpeed = 2;
         }
         else
         {
             cm.movement.maxForwardSpeed = 6;
             cm.movement.maxSidewaysSpeed = 6;
             cm.movement.maxBackwardsSpeed = 6;
             cm.movement.maxFallSpeed = 20;
         }
     }
 }

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 10chaos1 · Nov 11, 2014 at 05:02 AM 0
Share

thank you this helped out immensely

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Using C# and getcomponent... 1 Answer

C# how to make Character Motor Jump Infinitely Upward 2 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