- Home /
Question by
glenohumeral13 · Jun 20, 2014 at 02:27 AM ·
javascriptcharactercontrollercharactermotor
How do I switch the components from a character motor to a character controller?
I am trying to code some underwater functionality for my Unity game, but I am having trouble switching the CharacterMotor components to the CharacterController ones. This is my code:
#pragma strict
var waterLevel : float;
var myParticles : ParticleSystem;
private var isUnderwater : boolean;
private var normalColor : Color;
private var underwaterColor : Color;
private var charcontroller:CharacterController;
function Start ()
{
normalColor = new Color (0.5f, 0.5f, 0.5f, 0.5f);
underwaterColor = new Color (0.22f, 0.65f, 0.77f, 0.5f);
charcontroller = GetComponent(CharacterController);
myParticles.Stop();
GameObject.Find("Blob Light Projector").GetComponent(Projector).enabled = false;
}
function Update ()
{
if ((transform.position.y < waterLevel) != isUnderwater)
{
isUnderwater = transform.position.y < waterLevel;
if (isUnderwater) SetUnderwater ();
if (!isUnderwater) SetNormal ();
}
if(isUnderwater && Input.GetKey(KeyCode.E))
{
constantForce.relativeForce = Vector3(0,-200, 0);
}
else
{
constantForce.relativeForce = Vector3(0, 0, 0);
}
if(isUnderwater && Input.GetKey(KeyCode.Q))
{
constantForce.relativeForce = Vector3(0, 200, 0);
}
}
function SetNormal ()
{
RenderSettings.fogColor = normalColor;
RenderSettings.fogDensity = 0.05f;
GameObject.Find("Blob Light Projector").GetComponent(Projector).enabled = false;
}
**function SetUnderwater ()
{
RenderSettings.fogColor = underwaterColor;
RenderSettings.fogDensity = 0.08f;
charcontroller.Move.gravity = 2;
charcontroller.Move.maxFallSpeed = 5;
charcontroller.Move.maxForwardSpeed = 4;
charcontroller.Move.maxSidewaysSpeed = 4;
myParticles.Play();
GameObject.Find("Blob Light Projector").GetComponent(Projector).enabled = true;
}**
The bolded code is where the error is coming from. Here is a snapshot of the errors I'm getting: enter image description here
Any help would be really appreciated! Thanks!
screen shot 2014-06-19 at 4.31.05 pm.png
(46.9 kB)
Comment
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Collision Detection 0 Answers
Character Controller collision on Mesh Colliders Slopes Issue. 1 Answer
Character Controller moves forever after colliding with object 1 Answer
How would you implement a first-in first-out queue system in javascript? 0 Answers