You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Networking.Client;
public class CannonShot : MonoBehaviour
{
public bool shootingRight;
public ConnectedClients clientData;
GameObject player;
string charname;
public List<string> Names;
Rigidbody rb;
private void Start()
{
rb = this.gameObject.GetComponent<Rigidbody>();
for (int i = 0; i < clientData.AllClients.Count; i++)
{
Names.Add(clientData.AllClients[i].characterAnimal + "(Clone)");
}
}
IEnumerator PushLeftCoroutine(float time)
{
float elapsedTime = 0;
Vector3 startPosition = transform.position;
Vector3 endPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.0f);
time *= 0.8f;
yield return new WaitForSeconds(0.05f);
while (elapsedTime < time)
{
transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}
transform.position = endPosition;
Destroy(gameObject);
}
IEnumerator PushRightCoroutine(float time)
{
float elapsedTime = 0;
Vector3 startPosition = transform.position;
Vector3 endPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1.0f);
time *= 0.8f;
yield return new WaitForSeconds(0.05f);
while (elapsedTime < time)
{
transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}
transform.position = endPosition;
Destroy(gameObject);
}
void OnTriggerEnter(Collider other)
{
foreach (string name in Names)
{
if (other.gameObject.name == name)
{
rb.velocity = Vector3.zero;
player = GameObject.Find(charname);
Rigidbody playerRB = player.GetComponent<Rigidbody>();
if (shootingRight == true)
{
StartCoroutine(PushRightCoroutine(0.5f));
player.GetComponent<Character>().CannonRMove(0.5f);
}
else
{
StartCoroutine(PushLeftCoroutine(0.5f));
player.GetComponent<Character>().CannonLMove(0.5f);
}
}
}
}
}