Game Development Lab
Exp 5. Write a c# script to Destroy game objects Over Time (Object pooling).
Aim: Write a script to destroy a GameObject within a specific Time.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyOverTime : MonoBehaviour
{
public float lifeTime;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
/* lifeTime -= Time.deltaTime;
if(lifeTime< 0)
{
Destroy(gameObject);
} */
Destroy(gameObject, lifeTime);
}
}
Exp4. Write a C# script for damaging and killing the player depending on his health.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KillPlayer : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
LevelManager.instance.RespawnPlayer();
}
}
}
Exp.6. Write a c# script for smooth camera follow mechanism.
Aim: Create smooth camera transition with follow target functionality.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = newVector3(target.position.x, target.position.y,
transform.position.z);
}
}
Output
Comments
Post a Comment