init
This commit is contained in:
commit
3b4c6e0ec6
506 changed files with 434142 additions and 0 deletions
60
Assets/Scripts/PortalBullet.cs
Normal file
60
Assets/Scripts/PortalBullet.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PortalBullet : MonoBehaviour{
|
||||
|
||||
[SerializeField] float speed = 10f;
|
||||
[SerializeField, Range(1, 10)] float maxDistanceTravel = 5;
|
||||
|
||||
Transform verticalPortals;
|
||||
Transform horizontalPortals;
|
||||
Vector3 direction;
|
||||
Vector3 playerPosition;
|
||||
PlayerController player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
float targetAngle = Mathf.Atan2(1 * direction.x, 1 * direction.z) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.Euler(0f, targetAngle, 0f);
|
||||
|
||||
transform.position = Vector3.MoveTowards(transform.position, new Vector3(playerPosition.x, transform.position.y, playerPosition.z) + direction * maxDistanceTravel, speed * Time.deltaTime);
|
||||
|
||||
if (transform.position == new Vector3(playerPosition.x, transform.position.y, playerPosition.z) + direction * maxDistanceTravel){
|
||||
player.canShoot = true;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if(col.gameObject.tag == "LateralWalls"){
|
||||
if(direction == Vector3.right || direction == Vector3.left){
|
||||
horizontalPortals.gameObject.SetActive(true);
|
||||
player.canShoot = true;
|
||||
gameObject.SetActive(false);
|
||||
}else if(direction == Vector3.forward || direction == Vector3.back){
|
||||
verticalPortals.gameObject.SetActive(true);
|
||||
player.canShoot = true;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
AudioManager.instance.PlayOneShot("PortalPlace");
|
||||
}
|
||||
else{
|
||||
player.canShoot = true;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetImportantThings(Transform vPortals, Transform hPortals, Vector3 dir, Vector3 playerPos, PlayerController player){
|
||||
verticalPortals = vPortals;
|
||||
horizontalPortals = hPortals;
|
||||
direction = dir;
|
||||
playerPosition = playerPos;
|
||||
this.player = player;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue