Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

3DBuzz TP Camera ERRORS

Discussion in 'Scripting' started by tylernocks, Mar 25, 2013.

  1. tylernocks

    tylernocks

    Joined:
    Sep 9, 2012
    Posts:
    256
    The name `Helper' does not exist in the current context

    TP_Camera = TheCamera

    TheCamera Script
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TheCamera : MonoBehaviour
    5. {
    6.     public static TheCamera Instance;
    7.    
    8.     public Transform TargetLookAt;
    9.     public float Distance = 5f;
    10.     public float DistanceMin = 3f;
    11.     public float DistanceMax = 10f;
    12.     public float X_MouseSensitivity = 5f;
    13.     public float Y_MouseSensitivity = 5f;
    14.     public float MouseWheelMouseSensitivity = 5f;
    15.     public float Y_MinLimit = -40f;
    16.     public float Y_MaxLimit = 80f;
    17.  
    18.  
    19.  
    20.    
    21.    
    22.     private float mouseX = 0f;
    23.     private float mouseY = 0f;
    24.     private float startDistance = 0f;
    25.     private float desiredDistance = 0f;
    26.    
    27.    
    28.     void Awake()
    29.     {
    30.         Instance = this;
    31.     }
    32.  
    33.     void Start()
    34.     {
    35.         Distance = Mathf.Clamp(Distance, DistanceMin, DistanceMax);
    36.         startDistance = Distance;
    37.         Reset();
    38.     }
    39.    
    40.  
    41.     void LateUpdate()
    42.     {
    43.         if(TargetLookAt == null)
    44.             return;
    45.            
    46.             HandlePlayerInput();
    47.            
    48.             CalculateDesiredPosition();
    49.            
    50.             UpdatePosition();
    51.        
    52.     }
    53.    
    54.     void HandlePlayerInput()
    55.     {
    56.         var deadZone = 0.1f;
    57.        
    58.         if(Input.GetMouseButton(1))
    59.         {
    60.             mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity;
    61.             mouseY -= Input.GetAxis("Mouse Y") * Y_MouseSensitivity;
    62.         }
    63.        
    64.         // This is where we will limit mouseY
    65.         mouseY = Helper.ClampAngle(mouseY,Y_MinLimit,Y_MaxLimit);
    66.        
    67.        
    68.         if(Input.GetAxis("Mouse ScrollWheel") < -deadZone || Input.GetAxis("Mouse ScrollWheel") > deadZone)
    69.         {
    70.             desiredDistance = Mathf.Clamp(Distance - Input.GetAxis("Mouse ScrollWheel") * MouseWheelMouseSensitivity,
    71.                                           DistanceMin, DistanceMax);
    72.         }
    73.        
    74.     }
    75.    
    76.     void CalculateDesiredPosition()
    77.     {
    78.        
    79.     }
    80.        
    81.     void UpdatePosition()
    82.     {
    83.    
    84.     }
    85.  
    86.    
    87.     public void Reset()
    88.     {
    89.         mouseX = 0;
    90.         mouseY = 10;
    91.         Distance = startDistance;
    92.         desiredDistance = Distance;
    93.     }
    94.    
    95.    
    96.     public static void UseExistingOrCreateNewMainCamera()
    97.     {
    98.         GameObject tempCamera;
    99.         GameObject targetLookAt;
    100.         TheCamera myCamera;
    101.        
    102.         if(Camera.mainCamera != null)
    103.         {
    104.             tempCamera = Camera.mainCamera.gameObject;
    105.         }
    106.        
    107.         else
    108.         {
    109.             tempCamera = new GameObject("Main Camera");
    110.             tempCamera.AddComponent("Camera");
    111.             tempCamera.tag = "MainCamera";
    112.         }
    113.        
    114.         tempCamera.AddComponent("TheCamera");
    115.         myCamera = tempCamera.GetComponent("TheCamera") as TheCamera;
    116.        
    117.    
    118.        
    119.         targetLookAt = GameObject.Find("targetLookAt") as GameObject;
    120.        
    121.        
    122.         if(targetLookAt == null)
    123.         {
    124.             targetLookAt = new GameObject("targetLookAt");
    125.             targetLookAt.transform.position = Vector3.zero;
    126.         }
    127.        
    128.         myCamera.TargetLookAt = targetLookAt.transform;
    129.        
    130.        
    131.        
    132.        
    133.     }
    134. }
    135.  
    Helper script
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public static class Helper
    4. {
    5.     public static float ClampAngle(float angle, float min, float max)
    6.     {
    7.         do
    8.         {
    9.             if (angle < -360)
    10.                 angle += 360;
    11.             if (angle > 360)
    12.                 angle -= 360;
    13.         } while (angle < -360 || angle > 360);
    14.  
    15.         return Mathf.Clamp(angle, min, max);
    16.     }
    17. }
    What is wrong with it.
     
  2. Annihlator

    Annihlator

    Joined:
    Oct 15, 2012
    Posts:
    378
    There's no actual reference to helper.
    Unity only knows you want to use a function called Helper, but has no idea what or where this 'Helper' is.

    Also, the script file helper resides in is incomplete, try creating an empty script to see the structure and elements unity requires. (Mainly line 4 ;) )