Hello, i am making a Halo remake, and am working on the plasma grenade.
Intended function:
The player walks through a trigger(a floating, glowing, grenade) to set plasmaGernadeAmmo to True. This bool is stored in the gameManager, and referenced by the player object when ThrowGrenade is called.
Problem:
The player walks through the trigger, and the trigger reports using Debug.log that it changed the plasmaGernadeAmmo to true. The GameManager and Player object still reports using debug.log that its not true.
here is my three cripts. #1 is the trigger #2 is the GameManager #3 is the player object.
using UnityEngine;
using System.Collections;
public class GernadePickup : PlayerManager {
public void OnTriggerEnter(Collider other){
Debug.Log ("Plasma gernade touched. plasmaGernadeAmmo = " + plasmaGernadeAmmo);
plasmaGernadeAmmo = true;
Debug.Log ("UPDATE - plasmaGernadeAmmo = " + plasmaGernadeAmmo);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
public class PlayerManager : MonoBehaviour {
//this script will be used to determan if the player has ammo.
public bool plasmaGernadeAmmo;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log("PLayer Manager - plasmaGernadeAmmo = " + plasmaGernadeAmmo);
}
}
using UnityEngine;
using System.Collections;
public class GernadeThrow : PlayerManager {
public GameObject gernadePrefab;
private Camera mainCamera;
public bool hasGernade;
public float throwFource;
// Use this for initialization
void Start () {
mainCamera = Camera.main;
}
// Update is called once per frame
public void Update () {
Debug.Log ("plasmaGernadeAmmo = " + plasmaGernadeAmmo);
if(Input.GetButtonDown ("Fire1")){
Debug.Log ("Gernade Thrown Requested");
if(plasmaGernadeAmmo == true){
Debug.Log ("Plasma gernade Thrown");
ThrowGernade();
}
}
}
void ThrowGernade(){
Vector3 vec = mainCamera.ViewportToWorldPoint(new Vector3(0.5F, 0.5F, 0));
GameObject Gernade = (GameObject)Instantiate(gernadePrefab, vec, mainCamera.transform.rotation);
Gernade.rigidbody.AddForce(Gernade.transform.forward * throwFource);
//Gernade.rigidbody.velocity = transform.forward * throwFource;
}
}
I’m sorry for it being sloppy, I wanted to give it to you in its raw form.
If anyone has recommendations on how to do this in a better way, please tell ^.^