Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Bentoon · Jan 27, 2015 at 08:59 AM · c#variablescamera rotate

passing variables to control Camera position

Hello All,

I am moving a camera (myCamObj) and when I click on something (script #1) I record the cameras Vector3 Pos in a public variable (camPos)

Then it moves over and follows a path and then when it clicks on something else (script #2) I want it to return to the original place it left (which would still be 'camPos")

I also need to reset its rotation to forward

The variables are not being passed nor is the rotation realigning

Script #1

 using System.Collections;
 
 public class iTweenMouseUpPath : MonoBehaviour {
 
 
     public GameObject myCamObj;
     bool myTrigger = false;
     public Transform myQuad;
     // for use in another script
     public Vector3 camPos;
 
 
 
     //On mouseUp put camera on path
     void OnMouseUp () {
     //Record Camera Pos to be called by another script
         camPos= myCamObj.transform.position;
 
         Debug.Log ("camPos = " + camPos);
     //Then Move Camera
         //iTween.MoveTo(myCamObj, iTween.Hash("path", iTweenPath.GetPath("WLKPath"), "time", 15));
         iTween.PutOnPath(myCamObj, iTweenPath.GetPath("WLKPath"), 0);
     //Triger the look at in the Update Function
         myTrigger = true;
 
     }
 
     //Keep Cam looking at an Object
     void Update() 
         {
         if (myTrigger == true) 
             {
             myCamObj.transform.LookAt (myQuad);
             }
         }
 
 }


Script #2:

 using UnityEngine;
 using System.Collections;
 
 public class mouseUpBack2 : MonoBehaviour {
 
     public GameObject myCamObj;
     public Vector3 camPos;
     
     
     void OnMouseUp () {
         //Debug.Log ("camPos2 = " + camPos);
 
         myCamObj.transform.position = camPos;
         myCamObj.transform.rotation = Quaternion.Euler(0,0,0);
     }
 }
 

Thanks !

~be

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 wangunity · Jan 27, 2015 at 09:15 AM

I remember you answered my question.hehe...so coinsidence. if you want to assign value with campos. you should in the script 2 to get the first script, and obtain the campos value. below is a simple code. public class mouseUpBack2 : MonoBehaviour {

      public GameObject myCamObj;
      public Vector3 camPos;
      public iTweenMouseUpPath _itweenpath;
      
      void OnMouseUp () {
          //Debug.Log ("camPos2 = " + camPos);
 //IF the _itweenpath attach the current gameobject.
          _itweenpath = getcomponent<_itweenpath>(); 
          myCamObj.transform.position = _itweenpath.campos;
          myCamObj.transform.rotation = Quaternion.Euler(0,0,0);
      }
  }


wish to help you

Comment
Add comment · Show 3 · 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 Bentoon · Jan 27, 2015 at 05:32 PM 0
Share

Thank you wangunity

I didn't se your response until this A$$anonymous$$. Yes coincidence : )

I was asking a more general question about passing variables, but if this works switching iTween paths it might be very nice for me

I will check this now, Thanks!

~be

avatar image Bentoon · Jan 27, 2015 at 08:55 PM 0
Share

Hello

This isn't working for me yet. I get the following errors

Assets/mySCRIPTS/mouseUpBack2.cs(19,44): error CS0118: mouseUpBack2._itweenpath' is a field' but a `type' was expected

Thanks again

~be

avatar image Bentoon · Jan 27, 2015 at 11:17 PM 0
Share

So I modded the script

I'm starting to get it , but

I get the following Error in Console:

NullReferenceException: Object reference not set to an instance of an object mouseUpBack2.On$$anonymous$$ouseUp () (at Assets/mySCRIPTS/mouseUpBack2.cs:20) UnityEngine.Send$$anonymous$$ouseEvents:DoSend$$anonymous$$ouseEvents(Int32, Int32)

But I can see from the Debug.Log that camPos is being passed correctly The problem seems to be in the second to last line:

myCamObj.transform.position = camPosScript.camPos;

Both sides of the equation are vector3's I'm simply stating the camera position to the position held in the passed variable

 using UnityEngine;
 using System.Collections;
 
 public class mouseUpBack2 : $$anonymous$$onoBehaviour {
 
     public GameObject myCamObj;
     public Vector3 camPos;
     public iTween$$anonymous$$ouseUpPath camPosScript;
     
 
 
 
     void On$$anonymous$$ouseUp () {
         Debug.Log ("camPos2 = " + camPosScript.camPos);
 
         camPosScript = GetComponent<iTween$$anonymous$$ouseUpPath> ();
         myCamObj.transform.position = camPosScript.camPos;
         myCamObj.transform.rotation = Quaternion.Euler(0,0,0);
     }
 }
 


Thanks!

~be

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to add a variable to a prebuilt class? 1 Answer

Class Scope Variable 1 Answer

How to pass variables from one object in one scene to another object in another scene? 3 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