I have 2 scripts that are connected
script 1
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
public GameObject mine;
bool canplacemines;
public float numberofmines = 5f;
public bool canjump = true;
// Use this for initialization
void Start () {
canplacemines = true;
}
// Update is called once per frame
void Update () {
if (numberofmines > 0) {
canplacemines = true;
} else {
canplacemines = false;
}
while (canjump == false) {
transform.position += new Vector3 (0, -8 * Time.deltaTime, 0);
}
if (Input.GetKey (KeyCode.W) && canjump == true) {
transform.position += new Vector3 (0, 8 * Time.deltaTime, 0);
}
if (Input.GetKey (KeyCode.A) ) {
transform.position += new Vector3 (-6 * Time.deltaTime, 0, 0);
}
if (Input.GetKey (KeyCode.D) && canjump ) {
transform.position += new Vector3 (6 * Time.deltaTime, 0, 0);
}
if (Input.GetKeyDown (KeyCode.Space)) {
if (canplacemines = true) {
Instantiate (mine, transform.position, Quaternion.identity);
numberofmines--;
}
}
}
}
second
using UnityEngine;
using System.Collections;
public class noslip : MonoBehaviour {
public player _canjump;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "LevelBlocks") {
_canjump.canjump = false;
} else {
_canjump.canjump = true;
}
}
}
This script is used to make player not to be able to jump when he is touching the wall LevelBlocks . When my player touches the LevelBlocks unity has stoped working . pls help
↧