Is there anyway to move my camera only in x axis?
here’s my setting and movement code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float maxSpeed;
public float jumpPower;
Rigidbody2D rigid;
SpriteRenderer spriteRenderer;
Animator anim;
void Awake(){
rigid=GetComponent<Rigidbody2D>();
spriteRenderer=GetComponent<SpriteRenderer>();
anim=GetComponent<Animator>();
}
void Update(){
//Jump
if(Input.GetButtonDown("Jump")&&!anim.GetBool("isJump")){
rigid.AddForce(Vector2.up*jumpPower,ForceMode2D.Impulse);
anim.SetBool("isJump",true);
}
//Stop Speed
if(Input.GetButtonUp("Horizontal")){
rigid.velocity=new Vector2(rigid.velocity.normalized.x*0.5f,rigid.velocity.y);
}
//Direction Sprite
if(Input.GetButton("Horizontal"))
{
spriteRenderer.flipX=Input.GetAxisRaw("Horizontal")==-1;
}
//Animation
if(Mathf.Abs(rigid.velocity.x)<0.3)
{
anim.SetBool("isWalk",false);
}
else
{
anim.SetBool("isWalk",true);
}
}
void FixedUpdate(){
//Move Speed
float h=Input.GetAxisRaw(("Horizontal"));
rigid.AddForce(Vector2.right*h,ForceMode2D.Impulse);
//Max Speed
if(rigid.velocity.x>maxSpeed){
rigid.velocity=new Vector2(maxSpeed,rigid.velocity.y);
}
else if(rigid.velocity.x<maxSpeed*(-1)){
rigid.velocity=new Vector2(maxSpeed*(-1),rigid.velocity.y);
}
//Landing Platform
Debug.DrawRay(rigid.position,Vector3.down*1.25f,new Color(0,1,0));
RaycastHit2D rayHit=Physics2D.Raycast(rigid.position,Vector3.down*1.25f,1,LayerMask.GetMask("Platform"));
if(rayHit.collider!=null){
if(rayHit.distance<0.96f)
{
anim.SetBool("isJump",false);
}
}
}
}