Hello! :-)
I'm having trouble with my Camera.main, I want it to move towards player direction and to move right when player stops, for an value that is equal to players distance traveled.
With my code applied nothing happens, there are even no errors or anything it just isn't moving. I am missing something, but I can't see what?
Here is the method in a main script:
public void Scroll ()
{
// Distance between player and mainCamera
float relDist = - GameObject.FindWithTag ("Player").transform.localPosition.x + Camera.main.transform.localPosition.x;
Vector3 camDestination = new Vector3 (playerEndPosX + relDist,
Camera.main.transform.localPosition.y,
Camera.main.transform.localPosition.z);
Vector3 trans = Vector3.MoveTowards(Camera.main.transform.localPosition, camDestination, scrollSpeed * Time.time);
Camera.main.transform.localPosition = trans;
}
and a calling code in other script:
public class PlayerStopperListener : MonoBehaviour {
public GameStateListener gsl = null;
public StickController sc = null;
void OnTriggerExit2D (Collider2D collidedObject)
{
switch(collidedObject.tag)
{
case "Platform":
if(StickController.outcome)
{
gsl.onStateChange(PlayerStateController.GameStates.idle);
StickController.playerEndPosX = GameObject.FindWithTag("Player").transform.localPosition.x;
// TopEdgeListener script has set otcome to true
StickController.outcome = false;
if(GameObject.FindWithTag ("OldPlatform") != null)
{
GameObject.FindWithTag("OldPlatform").tag = "Deprecated";
}
if (GameObject.FindWithTag("StartPlatform") != null)
{
// Change tag of the StartPlatform
GameObject.FindWithTag("StartPlatform").tag = "OldPlatform";
}
// Change tag of the CurrentPlatform
if(GameObject.FindWithTag ("CurrentPlatform") != null)
{
GameObject.FindWithTag("CurrentPlatform").tag = "OldPlatform";
}
// Change tags of the old sticks to deprecated
if(GameObject.FindGameObjectsWithTag("OldStick") != null)
{
foreach(GameObject obj in GameObject.FindGameObjectsWithTag("OldStick"))
{
obj.transform.tag = "Deprecated";
}
}
if (GameObject.FindWithTag("bottomStickPivot") != null)
{
// Tag all gameobjects that are used for making the stick as OldStick
GameObject.FindWithTag("bottomStickPivot").tag = "OldStick";
GameObject.FindWithTag("Stick").tag = "OldStick";
GameObject.FindWithTag("topEdge").tag = "OldStick";
}
// Since this method is called every time when the Player change his state from moving to idle
// Eather case change a tag of the new platform to CurrentPlatform
GameObject.FindWithTag("Platform").tag = "CurrentPlatform";
StickController.instantiateNow = true;
**sc.Scroll ();**
}
break;
}
}
}
and Camera.main in a Inspector:
![alt text][1]
[1]: /storage/temp/41801-maincamera.png
↧