- Home /
Question by
fraubolat · Aug 04, 2020 at 05:27 PM ·
scripting problemraycastshootingraycastingproblem during runtime
scripting problem
hi so want i want is if the player pressed the button it should make a new spawn point and then if the player dies it should be his new spawn point. her are the script. i will really appricaite it and sry my English isn't that good
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawnponit : MonoBehaviour
{
public Movment movment;
int count = 1;
public bool exist = false;
public Vector3 a;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void schnapp()
{
if (movment.grounded == true && count > 0 )
{
exist = true;
a = movment.player.position;
Debug.Log(a);
count--;
}
else
{
return;
}
}
public void sdad()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class plazerhealth : MonoBehaviour
{
public AudioSource healing;
public Text a;
[Header("idk")]
public int health = 250;
public int currenthealth;
Rigidbody rb;
public float radius = 50F;
public float power = 1000F;
bool takinmgdamge= false;
float tracking;
public AudioSource hurtsound;
bool canheal = false;
int result;
public ParticleSystem heal;
public spawnponit Spawnponit;
public void Awake()
{
heal.Stop();
if (Spawnponit.exist == true)
{
if(currenthealth == 0)
{
transform.position = Spawnponit.a;
}
}
}
void Start()
{
rb = GetComponent<Rigidbody>();
currenthealth = health;
tracking = currenthealth;
}
void Update()
{
if (currenthealth <= 0)
{
Destroy(gameObject);
Explosion();
}
if(currenthealth <= 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
a.text = currenthealth.ToString();
}
private void FixedUpdate()
{
currenthealth = Mathf.Clamp(currenthealth, 0, 10000);
}
public void takedamge(int damge)
{
currenthealth -= damge;
hurtsound.Play();
}
private void OnCollisionEnter(Collision collision)
{
if(collision.collider.tag=="rocket")
{
currenthealth -= 40;
}
}
void Explosion()
{
Vector3 explosionPos = transform.position;
Collider[] colliderss = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider hit in colliderss)
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
rb.AddExplosionForce(power, explosionPos, radius, 3.0F);
}
}
public void reheal()
{
result = 250 - currenthealth;
currenthealth += result;
StartCoroutine(startheal());
healing.Play();
}
IEnumerator startheal()
{
heal.Play();
yield return new WaitForSeconds(1f);
heal.Stop();
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycast shooting 1 Answer
raycast is pointing in two directions? 1 Answer
Trouble with Raycast shooting 1 Answer
animation problem 1 Answer
How to Fix a Guns Firing Script so it Doesn't Constantly Fire 3 Answers