create a script for fighting game camera in unity in csharp

Here's one way to create a script for a fighting game camera in Unity using C#:

main.cs
using UnityEngine;

public class FightingGameCamera : MonoBehaviour
{
    public Transform target;
    public float distance = 4.0f;
    public float height = 1.0f;
    public float smoothSpeed = 0.125f;

    private Vector3 offset;

    private void Start()
    {
        offset = new Vector3(0, height, -distance);
    }

    private void LateUpdate()
    {
        Vector3 desiredPosition = target.position + offset;
        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
        transform.position = smoothedPosition;

        transform.LookAt(target);
    }
}
609 chars
26 lines

The script uses a Transform variable called target that determines which object the camera will follow. The distance and height variables control how far and high the camera is positioned from the target. The smoothSpeed variable is used to make the camera movement smoother.

In the Start function, we set the offset to a vector that points back and up from the target based on the distance and height variables.

In the LateUpdate function, we calculate the desiredPosition which is the position the camera would like to move to. We then use Vector3.Lerp to smoothly move the camera from the current position to the desired position based on smoothSpeed. Finally, we make the camera look at the target using transform.LookAt.

gistlibby LogSnag