Guest User

Untitled

a guest
Jul 1st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. ======
  3. Script on the bullet
  4. ======
  5.  
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9.  
  10. public class BulletScript : MonoBehaviour
  11. {
  12. public GameObject hitEffect;
  13. void OnCollisionEnter2D(Collision2D col){
  14. if (col.gameObject.CompareTag("Enemy")){
  15. col.gameObject.GetComponent<EnemyHealth>().TakeDamage(1);
  16. }
  17. else if (col.gameObject.CompareTag("Barrel")){
  18. col.gameObject.GetComponent<BarrelScript>().Explode();
  19. }
  20. Destroy(gameObject);
  21. //hit effect
  22. GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);
  23. Destroy(effect, .3f);
  24. }
  25. }
  26.  
  27. ======
  28. Script for the camera
  29. =====
  30.  
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using UnityEngine;
  34.  
  35. public class Lerpcamera : MonoBehaviour
  36. {
  37. public Transform[] poses;
  38. public bool moving;
  39. public float lerpTime;
  40. private int nextLevelCam = 0;
  41. Vector3 Offset = new Vector3(0, 0 , -10);
  42.  
  43. public static Lerpcamera instance;
  44.  
  45. void Awake(){
  46. instance = this;
  47. }
  48. //Just to make it easier to call it from other scripts, not actually necessary
  49.  
  50. public void MoveCamera(){
  51. nextLevelCam ++;
  52. moving = true;
  53. }
  54. //call this function to move the camera to the next position on the array
  55.  
  56. void Update(){
  57. Debug.Log(nextLevelCam);
  58. if(moving){
  59. transform.position = Vector3.Lerp(transform.position, poses[nextLevelCam].position + Offset, lerpTime * Time.deltaTime);
  60.  
  61. }
  62. if(transform.position == poses[nextLevelCam].position){
  63. moving = false;
  64. }
  65. }
  66. }
  67.  
  68. =====
  69. Script on the player
  70. =====
  71. if (Input.GetButtonDown("Fire1")){
  72. AudioManager.instance.Play("Shoot", Random.Range(1f, 1.3f), 1f);
  73. gunAnim.Play("recoil", -1, 0f);
  74. cameraShake.shakeDuration += .05f;
  75. GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
  76. //muzze flash
  77. GameObject muzzle = Instantiate(muzzleFlash, firePoint.position, firePoint.rotation);
  78. Destroy(bullet, 5f);
  79. Destroy(muzzle, .1f);
  80. bullet.GetComponent<Rigidbody2D>().AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);
  81.  
  82. }
  83.  
  84.  
  85. void OnTriggerEnter2D(Collider2D col){
  86. if (col.CompareTag("CamTrigger")){
  87. Lerpcamera.instance.MoveCamera();
  88. Destroy(col.gameObject);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment