- Home /
iTween Camera Path called from a mouseUp (c#)
Hi I'm new to C#
I'm trying to move my Camera along a certain Path using iTween when I click on a certain object
(eventually other objects will trigger other paths)
my MouseUp script is on the object I'll click on:
using UnityEngine;
using System.Collections;
public class iTweenMouseUp : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void onMouseUp()
{
Path_1;
}
}
My Camera move Path script is on the Camera:
I thought I should be triggering function "Path_1" with the mouseUp
using UnityEngine;
using System.Collections;
public class iTweenPathCamera : MonoBehaviour {
void Start () {
}
void Update () {
}
void Path_1()
{
iTween.MoveTo(gameObject, iTween.Hash ("path", iTweenPath.GetPath("New Path 1"), "time", 8, "easetype", iTween.EaseType.easeInOutSine));
}
}
Probably semantics Thanks ~ Be
Answer by robertbu · Jul 26, 2014 at 07:48 PM
You need to learn how to access other game objects:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
http://unitygems.com/script-interaction1/
For your specific situation (assuming you are using the main camera and did not change the tag), you can change line 18 to:
Camera.main.GetComponent<iTweenPathCamera>().Path_1();
Hey Robertbu Thanks but I get this error:
`iTweenPathCamera.Path_1()' is inaccessible due to its protection level
I know that this means I should put a "public" on line 12 of the next script,
public void Path_1()
and while I don't get the error anymore, it doesn't work...
Any ideas? I'm looking into the docs
Thanks for your help
~ Be
You've misspelled 'On$$anonymous$$ouseUp()'. It needs to have an upper case 'O'.
So Yes the above is working well.
but I want to go a step further
and add a new "On$$anonymous$$ouseUp" to trigger the Camera to follow a new iTween Path.
Second On$$anonymous$$ouseUp script (iTween$$anonymous$$ouseUp1) calls Path_2
using UnityEngine;
using System.Collections;
public class iTween$$anonymous$$ouseUp1 : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void On$$anonymous$$ouseUp()
{
Camera.main.GetComponent<iTweenPathCamera>().Path_2();
}
}
This is the Camera Script it has both Path 1 & 2 in it (each are triggered by clicking on an object) using UnityEngine; using System.Collections;
public class iTweenPathCamera : $$anonymous$$onoBehaviour {
void Start () {
}
void Update () {
}
public void Path_1()
{
iTween.$$anonymous$$oveTo(gameObject, iTween.Hash ("path", iTweenPath.GetPath("New Path 1"), "time", 12, "easetype", iTween.EaseType.easeInOutSine));
}
void Path_2()
{
iTween.$$anonymous$$oveTo(gameObject, iTween.Hash ("path", iTweenPath.GetPath("New Path 2"), "time", 12, "easetype", iTween.EaseType.easeInOutSine));
}
}
Thanks for your help !
~Be
In the first script add at the top of the file:
private bool firstTime = true;
Then your On$$anonymous$$ouseUp() can be:
if (firstTime) {
Camera.main.GetComponent<iTweenPathCamera>().Path_1();
firstTime = false;
}
else {
Camera.main.GetComponent<iTweenPathCamera>().Path_2();
}
For future additional issues, please open a new question. Follow-on questions are frequently not answered since questions marked answered or have a number of answers are frequently ignored by everyone expect possibly the person(s) who answered.
Also if you are going to extend this to more than two paths, it would be better to approach the problem differently.
Your answer
Follow this Question
Related Questions
Isometric Prespective camera drag/drop 0 Answers
How to Camera Rotation when UI is up? 0 Answers
Change a float value with the horizontal axis? 1 Answer
Camera bounds 0 Answers