Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ======
- Script on the bullet
- ======
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BulletScript : MonoBehaviour
- {
- public GameObject hitEffect;
- void OnCollisionEnter2D(Collision2D col){
- if (col.gameObject.CompareTag("Enemy")){
- col.gameObject.GetComponent<EnemyHealth>().TakeDamage(1);
- }
- else if (col.gameObject.CompareTag("Barrel")){
- col.gameObject.GetComponent<BarrelScript>().Explode();
- }
- Destroy(gameObject);
- //hit effect
- GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);
- Destroy(effect, .3f);
- }
- }
- ======
- Script for the camera
- =====
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Lerpcamera : MonoBehaviour
- {
- public Transform[] poses;
- public bool moving;
- public float lerpTime;
- private int nextLevelCam = 0;
- Vector3 Offset = new Vector3(0, 0 , -10);
- public static Lerpcamera instance;
- void Awake(){
- instance = this;
- }
- //Just to make it easier to call it from other scripts, not actually necessary
- public void MoveCamera(){
- nextLevelCam ++;
- moving = true;
- }
- //call this function to move the camera to the next position on the array
- void Update(){
- Debug.Log(nextLevelCam);
- if(moving){
- transform.position = Vector3.Lerp(transform.position, poses[nextLevelCam].position + Offset, lerpTime * Time.deltaTime);
- }
- if(transform.position == poses[nextLevelCam].position){
- moving = false;
- }
- }
- }
- =====
- Script on the player
- =====
- if (Input.GetButtonDown("Fire1")){
- AudioManager.instance.Play("Shoot", Random.Range(1f, 1.3f), 1f);
- gunAnim.Play("recoil", -1, 0f);
- cameraShake.shakeDuration += .05f;
- GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
- //muzze flash
- GameObject muzzle = Instantiate(muzzleFlash, firePoint.position, firePoint.rotation);
- Destroy(bullet, 5f);
- Destroy(muzzle, .1f);
- bullet.GetComponent<Rigidbody2D>().AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);
- }
- void OnTriggerEnter2D(Collider2D col){
- if (col.CompareTag("CamTrigger")){
- Lerpcamera.instance.MoveCamera();
- Destroy(col.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment