- Home /
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
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
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;
}
}
}
Your answer
Follow this Question
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