Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

can someone help me with fixing these scripts

$
0
0
public Slider WidthSlider; public GameObject tile; public GameObject end; public int width = 10; public int length = 10; List level; // Use this for initialization void Start () { level = new List (); CreateLevel (width, length); } public void ClearLevel() { int numberOfTiles = level.Count; while (numberOfTiles > 0) { Destroy (level [0]); level.RemoveAt (0); numberOfTiles = numberOfTiles - 1; } } public void Rebuild() { CreateLevel (width, length); } public void GetWidth() { length = Mathf.FloorToInt(WidthSlider.value); } public void CreateLevel(float Width, float Length) { ClearLevel (); for (int x = 0; x < Width; x = x + 1) { for (int z = 0; z < Length; z = z + 1) { GameObject newTile = Instantiate (tile); Vector3 newPosition = transform.position +new Vector3 (x, 0, -z); newTile.transform.position = newPosition; level.Add (newTile); } } GameObject newEnd = Instantiate (end); Vector3 endPosition = transform.position +new Vector3 (Mathf.CeilToInt(Width/2)-0.5f, 0, -(Length+5)+0.5f); newEnd.transform.position = endPosition; newEnd.transform.localScale = new Vector3 (Width, 1, 10); level.Add (newEnd); } // Update is called once per frame void Update () { } } /// script 2 using UnityEngine; using System.Collections; public class RandomColor : MonoBehaviour { Material myMaterial; public Color currentColor = Color.green; float nextSwitch = 0; public int thing = 0; public Collider BlackCollider; public float switchTime = 3; // Use this for initialization void Start () { MeshRenderer myRender = GetComponent (); myMaterial = Instantiate (myRender.material); myRender.material = myMaterial; myMaterial.color = currentColor; } // Update is called once per frame void Update () { if (Time.time > nextSwitch) { nextSwitch = Time.time + switchTime; currentColor = NewColor(); myMaterial.color = NewColor(); } } Color NewColor (){ float dice = Random.value; int choice = 0; if (dice > 0.85f) { choice = 1; } else if (dice > 0.8f){ choice = 2; } else if (dice > 0.7f){ choice = 3; } thing = choice; //Random.Range (0, 5); switch (choice) { case 0: BlackCollider.enabled = false; return Color.red; break; case 1: BlackCollider.enabled = true; return Color.black; break; case 2: BlackCollider.enabled = false; return Color.blue; break; case 3: BlackCollider.enabled = false; return Color.green; break; case 4: BlackCollider.enabled = false; return Color.yellow; break; case 5: return Color.magenta; break; } return Color.white; } } // script 3 using UnityEngine; using System.Collections; public class ColorEffect : MonoBehaviour { // Use this for initialization void Start () { } void OnCollisionEnter(Collision col) { RandomColor colorCube = col.gameObject.GetComponent (); if (colorCube != null) { if (colorCube.thing == 2) { BlueEffect (); } if (colorCube.thing == 3) { GreenEffect (); } } } // Update is called once per frame void Update () { } void BlueEffect(){ this.transform.position = this.transform.position - (Vector3.forward*4); Debug.Log("BLUE"); } void GreenEffect(){ this.transform.position = this.transform.position + (Vector3.forward*4); Debug.Log("You Dead bro"); } void RedEffect(){ } } // script 4 using UnityEngine; using System.Collections; public class PlayerWalk : MonoBehaviour { public float speed; private Rigidbody rb; void Start () { rb = GetComponent(); } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = (transform.right*moveHorizontal) + (transform.forward*moveVertical); rb.AddForce (movement * speed); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>