Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 naman159 · Aug 28, 2015 at 02:21 PM · c#unity 5error

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);
     //}
 
 }

Comment
Add comment · Show 2
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 NoseKills · Aug 28, 2015 at 02:43 PM 0
Share

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.

avatar image naman159 · Aug 28, 2015 at 04:22 PM 0
Share

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);



3 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · 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 naman159 · Aug 28, 2015 at 03:27 PM 0
Share

hey @$$anonymous$$lausjoensuu its right

avatar image KlausJoensuu · Aug 28, 2015 at 04:26 PM 0
Share

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

avatar image
0

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

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 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

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

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

31 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

Related Questions

NullReferenceException on Invoke in another class 1 Answer

tengo un problema con este script no puedo hacer que salte el personaje en un 2f,hi i have a problem making my chacter jump with this script 0 Answers

Time.deltatime not working. 1 Answer

Visual Studio 2015 keeps crashing... 1 Answer

error CS0201 1 Answer


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