So I have a controller script where I only want to destroy the game object when it matches tags and I happen to be using an ability. This ability is slam. However even though I have it programmed to need both conditions in order to destroy, the platform gets destroyed whether im using slam or not. no matter what. Please help.
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace UnityStandardAssets.Vehicles.Ball
{
public class Ball : MonoBehaviour
{
// variables
public float basespeed;
public float jumppower;
public float sprintspeed;
public float currentspeed;
public float slampower;
private Rigidbody rb;
private const float k_GroundRayLength = .8f; // The length of the ray to check if the ball is grounded.
public bool slam;
public bool grounded;
//function start
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
public void Move(Vector3 moveDirection, bool jump){
{
// basic movement
rb.AddForce (moveDirection * currentspeed);
}
}
void Update (){
{
//jumping sequence
if (Physics.Raycast (transform.position, -Vector3.up, k_GroundRayLength) && (Input.GetKeyDown (KeyCode.Space)))
rb.AddForce (new Vector3 (0, jumppower, 0));
}
{ //sprint sequence
if (Physics.Raycast (transform.position, -Vector3.up, k_GroundRayLength) && (Input.GetKey (KeyCode.LeftShift)))
currentspeed = sprintspeed;
else
currentspeed = basespeed;
}
{
if (Physics.Raycast (transform.position, -Vector3.up, k_GroundRayLength))
grounded = true;
else
grounded = false;
}
//Slam Sequence
{
if (Input.GetKeyDown (KeyCode.Q) && (grounded == false))
slam = true;
{
if (slam == true)
rb.AddForce (new Vector3 (0, slampower, 0));
}
}
}
void OnTriggerEnter(Collider collider)
{
{
if ((slam == true) && (collider.gameObject.tag == "Destroy"))
Destroy (GameObject.FindGameObjectWithTag ("Destroy"));
}
{
if (slam == true)
slam = false;
}
}
}
}