Circle (main).cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
Transform trans;
Transform camTrans;
Rigidbody2D rid2d;
float speed = 10;
int SpaceCount = 1;
int coincount = 0;
// Start is called before the first frame update
void Start()
{
trans = GetComponent<Transform>();
camTrans = GameObject.Find("Main Camera").GetComponent<Transform>();
rid2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame b
void Update()
{
if (Input.GetKey(KeyCode.D))
{
trans.Translate(new Vector3(1, 0, 0) * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.A))
{
trans.Translate(new Vector3(-1, 0, 0) * Time.deltaTime * speed);
}
if(SpaceCount < 3)
{
if (Input.GetKeyDown(KeyCode.Space))
{
SpaceCount++;
rid2d.AddForce(new Vector2(0f, 5f) , ForceMode2D.Impulse);
}
}
if(rid2d.velocity == Vector2.zero)
{
SpaceCount = 1;
}
}
public void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag.Equals("ujini is coin"))
{
Destroy(collision.gameObject,0.2f);
coincount++;
}
}
}
cameraMove.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraMove : MonoBehaviour
{
public Transform playerTransform;
Transform trans;
float position=0;
float transposition = 0;
// Start is called before the first frame update
void Start()
{
playerTransform = GameObject.Find("Player").GetComponent<Transform>();
trans = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
if(trans.position.x < playerTransform.position.x)
{
position = playerTransform.position.x - trans.position.x;
transposition = trans.position.x;
transposition += position;
}
}
}