简体   繁体   中英

How to rotate camera around the player after level up in Unity

I am making a simple game in unity and I want when level up, simple when player trigger to collider, Camera start rotate around the player.

How can I do this?

I am using C# script, and I assign a camera and player to it. My code is not working yet.

This is my Code here:

public Camera MainCam;
public GameObject target;

if (!failLevel && !level_up)
{
    MainCam.transform.RotateAround(target.transform.position, new Vector3(0.0f, 1.0f, 0.0f), 10 * Time.deltaTime);
    failLevel = true;

    gameEnd = true;
}

You need to rotate it in the Update function. This code will run only once. Try something like this:

if (!failLevel && !level_up) {
    rotateAround = true;
    failLevel = true;
    gameEnd = true;
}

void Update()
{
    if(rotateAround) {
        MainCam.transform.RotateAround(target.transform.position, new Vector3(0.0f, 1.0f, 0.0f), 10 * Time.deltaTime);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM