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 BlazedBear · Apr 15, 2016 at 08:06 AM · camerascripting problemtarget

Having trouble with a third person camera script

I have been following a ton of tutorials because I'm new to Unity and I feel like I've gotten the hang of it, but while making a third person script for a game I'm making for my collegeclass I ran into some errors that I'm not sure how to fix. The only thing I can come up with that's missing is a LookAt reference but I can't figure out how to fix that at this point, I'd love all the help I can get.

The errors I get: 6x Some scripts have compilation errors which may prevent obsolete API usages to get updated. Obsolete API updating will continue automatically after these errors get fixed. and 1x Assets/ThirdPersonCameraScript.cs(23,38): error CS0176: Static member `UnityEngine.Camera.main' cannot be accessed with an instance reference, qualify it with a type name instead 1x Error CS0176 Member 'Camera.main' cannot be accessed with an instance reference; qualify it with a type name instead

This is my script:

using UnityEngine; using System.Collections;

public class ThirdPersonCameraScript : MonoBehaviour { private const float Y_ANGLE_MIN = 0.0f; private const float Y_ANGLE_MAX = 50.0f;

 public Transform lookAt;
 public Transform camTransform;

 private Camera Cam;

 private float distance = 10.0f;
 private float currentX = 0.0f;
 private float currentY = 0.0f;
 private float sensitivityX = 4.0f;
 private float sensivityY = 1.0f;

 private void start()
 {
     camTransform = transform;
     Cam = GetComponent<Camera>().main;

 }

 private void Update()
 {
     currentX += Input.GetAxis("Mouse X");
     currentY += Input.GetAxis("Mouse Y");

     currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
 }


 private void LateUpdate()
 {
     Vector3 dir = new Vector3(0, 0, -distance);
     Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
     camTransform.position = lookAt.position + rotation * dir;
     camTransform.LookAt(lookAt.position);
 }
 

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Apr 16, 2016 at 08:55 PM

I'm not sure what you want to do with the cam variable but the reference is a bit strange. If you want a reference to the main camera use: Camera.main

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

65 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 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 avatar image avatar image avatar image

Related Questions

Centering camera between my player and a selected object. 0 Answers

Script able to target two cameras? 0 Answers

How to script a random asset generator> 0 Answers

How can I get all cameras enabled true false states ? 0 Answers

Boolean variable is never true, even if declared true or ticked in the inspector 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