- Home /
Question by
Haydawg9872 · May 13, 2014 at 01:27 AM ·
projectilelimitationsrocks
Projectile Limiting for FPS
I am making a game where you pick up rock to throw at the enemies. Right now you can pick up the rocks and it tells how many rocks you have on the screen, but you throw infinite rocks. What could I do to limit the amount of rocks to the amount you collected? Script for player:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float movementSpeed = 5.0f;
public float mouseSensitivity = 7.0f;
float verticalRotation = 0;
public float UpDownRange = 60.0f;
public GUIText countText;
private int count;
// Use this for initialization
void Start ()
{
Screen.lockCursor = true;
count = 1;
SetCountText ();
}
// Update is called once per frame
void Update ()
{
//rotations
float rotLeftRight = Input.GetAxis ("Mouse X");
transform.Rotate (0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis ("Mouse Y");
verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange);
Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
//movement
float forwardspeed = Input.GetAxis ("Vertical") * movementSpeed;
float sidespeed = Input.GetAxis ("Horizontal") * movementSpeed;
Vector3 speed = new Vector3 (sidespeed, 0, forwardspeed);
speed = transform.rotation * speed;
CharacterController cc = GetComponent<CharacterController> ();
cc.SimpleMove (speed);
}
void OnTriggerEnter(Collider other)
{
countText.text = "Rocks: " + count.ToString ();
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive (false); count = count + 1; SetCountText ();
}
}
void SetCountText (){ }
}
...........Script for picking up rocks:
using UnityEngine;
using System.Collections;
public class PickUpScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive (false);
}
}
}
..................Script for throwing rocks:
var theBullet : Rigidbody;
var Speed = 20;
function Update () {
if (Input.GetMouseButtonDown(0))
{
var clone = Instantiate(theBullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));
Destroy (clone.gameObject, 3);
}
}
Comment
I didn't read your code but onThrow:
rocks --;
A quick glance at your code makes me wonder, are you asking how to reference a variable in Script A from Script B?