Hey guys. I’ve been working on the 2D Gameplay Tutorial and am looking to make a few changes. Hopefully you guys can help me out
-
Using the scripts that come with it, you can control both Lerpz and a spaceship by clicking on their corresponding button in a box in the top left. I wanted to know how to make it so I could walk up to the ship as Lerpz, press a key and enter the ship instead. Any help on this would rock =).
-
There are platforms that move between two points. How would I go about making them stationary, and only moving when Lerpz is on them, as well as adding a bit of lag so they stop for a second or so at each endpoint. Y’know, like the typical side-scroller elevator. 8)
-
Also, I know this is incredibly nooby of me, but I also need an example script of how to map keys to certain functions (for example, pressing “g” to toggle gravity and such.
Thanks in advance,
Tyler.
Thanks a ton man, but I don’t have the faintest idea how to code that.:shock: Could you post an example script or 2 for me?
Here’s one script. It goes on the player and you call it from the ship.
using UnityEngine;
using System.Collections;
public class PlayerEnterShip : MonoBehaviour {
private Renderer[] renderers;
private MonoBehaviour[] scripts;
void Start () {
renderers = GetComponentsInChildren<Renderer>(); //Gather all the Renderers
scripts = GetComponentsInChildren<MonoBehaviour>(); // Gather all the scripts
}
void Disappear () {
foreach (Renderer ren in renderers) {
ren.enabled = false;
}
foreach (MonoBehaviour script in scripts) {
script.enabled = false;
}
}
void Appear () {
foreach (Renderer ren in renderers) {
ren.enabled = true;
}
foreach (MonoBehaviour script in scripts) {
script.enabled = true;
}
}
}
I was going to write it in Javascript, but I got a strange casting error so here it is in C#. I’ll work on the next one, but here’s this so you don’t have to wait.
Thanks Peter. I’m looking forward to the next one .
I am going to really busy for the next couple of days so this should help get you started. I’ll post when I can.
C# version. This all goes inside a class named whatever you want.
void OnCollisionEnter(Collision col) {
if(col.gameObject.CompareTag("Player")) {
//Run movement stuff. Use Time.time and subtraction to figure out how long it has
// been standing in one place.
}
}
Javascript version.
function OnCollisionEnter(col : Collision) {
if(col.gameObject.CompareTag("Player")) {
//Run movement stuff. Use Time.time and some subtraction to figure out how
// long it has been standing in one place.
}
}