- Home /
how d you change PlatformEffector2D rotationaloffset change as prefabs in android?
So i'm creating a 'platformer' android game. in my game, there is a oneway platform that enables player to stand on top of it from below. i want to make player able to go down the platform when 'Jump' button and left analog is tilted on -y coordinate. i did make it and turn it into a prefabs. As i do some test somehow the script only affect the last object i put in the scene, so if there is platform A, and copied it as platform B, Platform A won't have its rotationaloffset changed, while platform B is working. and if i copied one more time as platform C, platform B stopped working while C is working. when i try to Debug.log(GameObject.name) , the last one ( Platform C in this case ) is the only debug that printed.
here is a snippet of my 'platform' code
public class half_bridge : MonoBehaviour
{
private PlatformEffector2D effector;
private bool drop;
public bool sc;
private void Start()
{
effector = this.GetComponent<PlatformEffector2D>();
}
private void Update()
{
sc = FindObjectOfType<btn_jump>().GetComponent<btn_jump>().get_droptrigger();
/*
this works but impossible for phones :(
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("sc." + this.gameObject.name);
dropping();
FindObjectOfType<btn_jump>().GetComponent<btn_jump>().dis_droptrigger();
}
*/
if (sc)
{
Debug.Log("sc." + this.gameObject.name);
dropping();
FindObjectOfType<btn_jump>().GetComponent<btn_jump>().dis_droptrigger();
}
}
public void dropping()
{
Debug.Log("drop");
effector.rotationalOffset = 180f;
StartCoroutine(backtozero());
}
IEnumerator backtozero()
{
yield return new WaitForSeconds(0.5f);
effector.rotationalOffset = 0f;
}
}
and this is my jumpbutton code
public class btn_jump : MonoBehaviour ,IPointerDownHandler
{
private bool pointerdown;
private bool drop;
public bool droptrigger;
private void Update()
{
drop = GameObject.FindGameObjectWithTag("player").GetComponent<CharacterController>().isdrop();
if (pointerdown)
{
if (!drop)
{
jump();
}
else
{
dropping();
}
pointerdown = false;
}
}
public void OnPointerDown(PointerEventData eventData)
{
pointerdown = true;
}
void dropping()
{
droptrigger = true;
//FindObjectOfType<half_bridge>().dropping();
}
void jump()
{
FindObjectOfType<CharacterController>().jump();
}
public void dis_droptrigger()
{
droptrigger = false;
}
public bool get_droptrigger()
{
return droptrigger;
}
}
Using Input.getkeydown(keycode.p) works as i want it to be, but it imposibble on phone. can you help me ?