public GameObject Shadow; //Cień void Start() { //Dołączenie do obiektu odpowiednich komponentów Player = GameObject.Find("Player").GetComponent <Transform>(); rgb2d = gameObject.GetComponent <Rigidbody2D>(); audioSource = gameObject.GetComponent <AudioSource>(); cam = GameObject.Find("Main Camera").GetComponent <Camera_Following>(); if (audioClip != null) { audioSource.clip = audioClip; audioSource.Play(); } if (shouldShakeCameraOnStart) { cam.ShakeCamera(ShakePow, ShakeDur); } if (gameObject.GetComponentInChildren <ParticleSystem>() != null) { particle = gameObject.GetComponentInChildren <ParticleSystem>(); spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); } if (Shadow != null) { Instantiate(Shadow, transform); } }
// Update is called once per frame void Update() { distCam = Vector3.Distance(cam.transform.position, transform.position); if (audioSource != null) { dist = Vector3.Distance(Player.position, transform.position); if (dist < 1000) { audioSource.volume = 1 - (dist / 1000); if (transform.position.x > cam.transform.position.x) { audioSource.panStereo = (distCam / 1000); } else { audioSource.panStereo = (distCam / -1000); } } else { audioSource.volume = 0; } } //Zniszczenie obiektu z danym efektem TimeToDestroy -= Time.deltaTime; if (TimeToDestroy <= 0) { if (audioSource != null) { audioSource.Stop(); } if (shouldShakeCamera) { cam.ShakeCamera(ShakePow, ShakeDur); } if (shouldAppear) //jeżeli coś ma się pojawić to w tym momencie { Instantiate(ObjectToApper, transform.position, transform.rotation); shouldAppear = false; } DestroyObj(); } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Enemy") //zadanie obrażeń przeciwnikowi / niszczenie obiektu { Enemy enemy = other.GetComponent <Enemy>(); if (!enemy.Dead) { if (shouldShakeCamera) { cam.ShakeCamera(ShakePow, ShakeDur); } DestroyObj(); if (ShouldAppearObject) { Instantiate(ObjectToAppear, transform.position, transform.rotation); } if (ShouldAppearObjectOnEnemy) { Instantiate(ObjectToAppearOnEnemy, PointToAppearObj.position, transform.rotation); } enemy.getDmg(dmg, DmgType, percentageDistribution); if (HasAMeeleDMG) { Vector3 point; point = other.gameObject.GetComponent <Collider2D>().bounds.ClosestPoint(transform.position); if (transform.position.x > enemy.transform.position.x) { Instantiate(enemy.blood, point, enemy.transform.rotation); } else { Instantiate(enemy.bloodBack, point, enemy.transform.rotation); enemy.CheckYourBack(); } } } } if (other.tag == "FlyerEnemy") { if (shouldShakeCamera) { cam.ShakeCamera(ShakePow, ShakeDur); } DestroyObj(); if (ShouldAppearObject) { Instantiate(ObjectToAppear, transform.position, transform.rotation); } } //niszczenie obiektu if (other.tag == "Walls") { if (shouldShakeCamera) { cam.ShakeCamera(ShakePow, ShakeDur); } DestroyObj(); if (ShouldAppearObject) { Instantiate(ObjectToAppear, transform.position, transform.rotation); } } if (other.tag == "Ground") { if (shouldShakeCamera) { cam.ShakeCamera(ShakePow, ShakeDur); } if (ShouldAppearObject) { Instantiate(ObjectToAppear, transform.position, transform.rotation); } DestroyObj(); } }