The name does not exist in the current context
I am new to unity as well as c# and heres a problem im getting from a long time. here is my code and there some problem with 'CameraTurn'
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class Charanim : MonoBehaviour {
[SerializeField]
private Animator animator;
[SerializeField]
private float DirectionDampTime = .25f;
private float speed = 0.0f;
private float h = 0.0f;
private float v = 0.0f;
public float ColliderHeight = 0.0f;
public float smoothTime = 0.3F;
private bool run = false;
private bool jump = false;
private bool IsGrounded = true;
private bool ButtonPress = false;
public ButtonTurn ButtonTurn;
public CameraTurn CameraTurn=null;
public float jumpHeight = 3000.0f;
CapsuleCollider capsule;
// Use this for initialization
void Start ()
{
ButtonTurn = GetComponent<ButtonTurn>();
CameraTurn = GetComponent<CameraTurn>();
animator = GetComponent<Animator>();
capsule = GetComponent<CapsuleCollider>();
//box = GetComponent<BoxCollider>();
run = false;
if(animator.layerCount >= 2)
{
animator.SetLayerWeight(1, 1);
}
}
void OnCollisionEnter(Collision collider)
{
IsGrounded = true;
print ("grounded");
}
// Update is called once per frame
void Update () {
if(animator)
{
h = Input.GetAxis("Horizontal");
speed = Input.GetAxis("Vertical");
CheckButton ();
CheckRun ();
CheckJump ();
if ((h>=.1)||(h<=-.1))
{
transform.Rotate(0,(h*2),0);
}
animator.SetFloat("speed", speed);
animator.SetFloat("direction", h, DirectionDampTime, Time.deltaTime);
}
}
public void CheckButton()
{
if ((speed>=.1)||(h>=.1)||(h<=-.1))
{
animator.SetBool("directionPress", true);
ButtonPress = true;
CameraTurn.enabled = true;
ButtonTurn.enabled = false;
}
else
{
animator.SetBool("directionPress", false);
ButtonPress = false;
CameraTurn.enabled = false;
ButtonTurn.enabled = true;
}
}
public void CheckRun()
{
if (Input.GetKey (KeyCode.LeftShift))
run = true;
else
run = false;
if (run == true)
{
animator.SetBool("RunCheck", true);
}
if (run == false)
{
animator.SetBool("RunCheck", false);
}
}
public void CheckJump()
{
if (Input.GetKey(KeyCode.Space))
{
jump = true;
}
else
jump = false;
if (jump == true)
{
animator.SetBool("jump", true);
if(capsule)
{
StartCoroutine("JumpCollider");
}
}
else //if (jump == false)
{
animator.SetBool("jump", false);
}
}
//IEnumerator JumpCollider()
//{
//yield return new WaitForSeconds(0.5f);
//capsule.height = 2;
//capsule.center = new Vector3(0.0f, 4.0f,0.0f);
//rigidbody.AddForce(0,jumpHeight,0);
//yield return new WaitForSeconds(0.3f);
//capsule.height = 6;
//capsule.center = new Vector3(0.0f, 2.9f,0.0f);
//}
}
When you get any type of error/exception while program$$anonymous$$g (with Unity or any other IDE) and want to ask for help, it's important to copy-paste the actual error message for others to see. It usually contains the exact line number and involved variables / classes in it and makes pinpointing the problem a lot easier for others. You can do this in the console window, which can be opened by clicking the error message at the bottom of the Unity3D window or from the window-dropdown in the top menu bar.
That being said, the error just means that the compiler can't find the class CameraTurn. $$anonymous$$ake sure you haven't misspelled the class name in this class or in the CameraTurn class and make sure the CameraTurn class is declared in a file called CameraTurn.cs and is public ( public class CameraTurn ...
) and if it is a nested class, you have to refer to it through the nesting class name.
hey @Nose$$anonymous$$ills actually im new at c# and unity so could u please specify what should i send shiould i even send the other script CameraTurn??
var target : Transform;
var rotSpeed : float;
function Update(){
var targetPos = target.position;
targetPos.y = transform.position.y; //set targetPos y equal to $$anonymous$$e, so I only look at my own plane
var targetDir = Quaternion.LookRotation(-(targetPos - transform.position));
transform.rotation = Quaternion.Slerp(transform.rotation, targetDir, rotSpeed*Time.deltaTime);
Answer by KlausJoensuu · Aug 28, 2015 at 03:08 PM
Make sure you're camera is called "CameraTurn". And check through code to see if all caps match.
Ok so its hard to say what the problem is if i cant see more of you're project. Post a few screen shots of full character controller script and character game object (select you're player and take a screen shot of you're inspector. Do the same for you're player camera. ) Ill take a look and see if i notice anything out of the ordinary. @naman159
Answer by NoseKills · Aug 29, 2015 at 11:35 AM
If what you posted in your second comment is the CameraTurn scrip, the problem is that you are mixing unity script and C#. You can't use a Unity script class in a c# scipt just like that. It would make things a lot easier if you'd just stick with either language, but if you can't, check this
Answer by tauqeerahmed · Aug 29, 2015 at 08:35 PM
Put the actual error or highlight the error here rather than posting the whole script so that other member get the idea about the error and solve for u
Your answer
Follow this Question
Related Questions
NullReferenceException on Invoke in another class 1 Answer
Time.deltatime not working. 1 Answer
Visual Studio 2015 keeps crashing... 1 Answer
error CS0201 1 Answer