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 /
avatar image
0
Question by Novrick · Sep 13, 2011 at 09:41 AM · cameramove

Move the camera

I'm working on a code, if playercontroller = false...then you can move the camera.

but the camera won't work =/

here's the code:

using UnityEngine; using System.Collections;

public class Cammouse : MonoBehaviour {

 public float Cameraspeed;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     
     if(Player.Playercontroller == false)
     {
         
         float camMoveH = Input.GetAxis("Horizontal") * Cameraspeed * Time.deltaTime;
         transform.Translate(Vector3.right * camMoveH);
         
         float camMoveV = Input.GetAxis("Vertical") * Cameraspeed * Time.deltaTime;
         transform.Translate(Vector3.down * camMoveV);
         
     }
     
     //transform.position = new Vector3(Input.mousePosition.x,Input.mousePosition.z);
 
 }

}

and this is the Player code were I made the bool for Playercontroller:

 using UnityEngine; using System.Collections;
 
 public class Player : MonoBehaviour {
 
 private float TimeDifference;
 
 public static int Health = 100;
 
 public float Playerspeed;
 
 public static bool Playercontroller = false;
 
 
 public static Player Instance;
 // Use this for initialization
 void Awake () 
 {
     Instance=this;
 }
 
 // Update is called once per frame
 void Update () {
 
 
 
     if (Playercontroller == true)
     {
     float amtToMoveH = Input.GetAxis("Horizontal") * Playerspeed * Time.deltaTime;
     transform.Translate(Vector3.right * amtToMoveH);
     float amtToMoveV = Input.GetAxis("Vertical") * Playerspeed * Time.deltaTime;
     transform.Translate(Vector3.forward * amtToMoveV);
 
     }

Comment
Add comment · Show 1
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 timberlandboots · Sep 21, 2011 at 12:00 PM 0
Share

====( http://www.clothes6.us )=====

online store wholesale sneakers,Jerseys, jewelry, glasses, shirt, sports,handbags,clothes ,news, vogue,jeryse at ugg boots,luxury fashion ysl women boots, christian louboutin boots,ed hardy clothes, jordan shoes,nike shoes,hoodies,t-shirts,nfl jerseys,mlb jerseys,nhl jerseys,coach handbags,handbags,wholesale, retail, sunglasses,belts, caps, ed hardy caps,suit,fashion good,newest style goods All the products are free shipping,

====( http://www.clothes6.us )=====

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

$$anonymous$$BT shoes 48

NFL jersys 24

NBA jersys 24

Timberland boots 45

Christan Audigier bikini $20

Ed Hardy Bikini $23

Smful short_t-shirt_woman $14

ed hardy short_tank_woman $15

Sandal $26

christian louboutin $60

Sunglass $14

COACH_Necklace $18

handbag $33

AF tank woman $16

====( http://www.clothes6.us )=====

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by syclamoth · Sep 14, 2011 at 03:26 AM

The problem is that you are accessing the Player as a static class! it would be simpler and generally easier to debug if you just put a reference to the player in your camera script:

 public Player player;

if you put this at the top, you can assign the Player in the unity editor, and then it will work for you. Just use the non-capitalised player instance reference instead of the capitalised Player class reference!

Comment
Add comment · Show 8 · 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 Novrick · Sep 14, 2011 at 07:13 AM 0
Share

so I should remove the static from the bool, write down public Player player in the upper part of the cam script and change the name of the class reference in the if statement?

avatar image syclamoth · Sep 14, 2011 at 07:16 AM 0
Share

Yep! After you do that, remember to assign the player in the editor, otherwise you'll just get null reference exceptions.

avatar image syclamoth · Sep 14, 2011 at 07:29 AM 0
Share

Just out of interest, are you instantiating the player, or is it in the scene from startup?

avatar image Novrick · Sep 14, 2011 at 07:33 AM 0
Share

well, now I can move the camera...but lost control of the player =/

avatar image syclamoth · Sep 14, 2011 at 07:39 AM 0
Share

Isn't that what you wanted? That you can either control the camera, or the player?

Show more comments
avatar image
0

Answer by japanitrat · Sep 13, 2011 at 10:08 AM

you are missing a part of your script, namely the one where "Player" and "Playercontroller" is defined. I guess though, that Player.Playercontroller is an instance of something, so you need to check against null and not false:

 if(Player.Playercontroller == null)
 {
     // ...
 }
Comment
Add comment · Show 5 · 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 Novrick · Sep 13, 2011 at 10:46 AM 0
Share

well, Playercontroller is a bool I set in the Player script to "true".

and if if this bool is true, I can control the player object.

I tried to change false to "null", but it seems to make the scripts unreachable =/

avatar image japanitrat · Sep 13, 2011 at 11:43 AM 0
Share

Please provide the code where "Player" is defined.

avatar image Novrick · Sep 13, 2011 at 11:52 AM 0
Share

Here's the player code:

using UnityEngine; using System.Collections;

public class Player : $$anonymous$$onoBehaviour {

 private float TimeDifference;
 
 public static int Health = 100;
 
 public float Playerspeed;
 
 public static bool Playercontroller = false;
 
 
 public static Player Instance;
 // Use this for initialization
 void Awake () 
 {
     Instance=this;
 }
 
 // Update is called once per frame
 void Update () {
     
     
     
     if (Playercontroller == true)
     {
     float amtTo$$anonymous$$oveH = Input.GetAxis("Horizontal") * Playerspeed * Time.deltaTime;
     transform.Translate(Vector3.right * amtTo$$anonymous$$oveH);
     float amtTo$$anonymous$$oveV = Input.GetAxis("Vertical") * Playerspeed * Time.deltaTime;
     transform.Translate(Vector3.forward * amtTo$$anonymous$$oveV);
         
     }
avatar image japanitrat · Sep 13, 2011 at 12:10 PM 0
Share

Please Edit your original question and pull the code from here to there as it makes it easier to read. Also please format the code correctly (just select all code in the text and hit the button with the zeros and ones above the textarea

avatar image Novrick · Sep 13, 2011 at 01:17 PM 0
Share

ok, I'll fix it

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate cam with object, smooth boost and brake 3 Answers

MoveTowards problem 1 Answer

show a camera in one monitor and another camera in another monitor 1 Answer

Make Arms Move Slow 0 Answers

Stop Motion Camera Effect 0 Answers


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