Hi
I wish make some simples changes to some lines of my code but because I know nothing about C # I can’t. ![]()
So I ask help here.
Here is my script for player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Script_player : MonoBehaviour {
public Text AfficheInfoPerso;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update()
{
Vector3 newpos = transform.position;
newpos.x += Input.GetAxis(“Horizontal”) / 20;
if (newpos.x < -6.5f) newpos.x = -6.5f;
if (newpos.x > 11.7f) newpos.x = 11.7f;
transform.position = newpos;
}
}
(Sorry I don’t know how insert code in forum. If someone can tell me how, that would be great!).
I wish my player moove automatically in the axe X, in the right direction. And when I press space, he change his direction to go at the left.
So I suppose the line to change it’s “newpos.x += Input.GetAxis(“Horizontal”) / 20;” to have newpos.x which increase alone. But I don’t know what write for do that.
I suppose for space button, I need to create a condition (move_at_left for exemple) and if it’s true, newpos.x decrease. But same, I don’t know what write.
2e point. This is my script for magic portal which teleport player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleporteur_2 : MonoBehaviour {
public Transform Other;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == “Player”)
{
collision.transform.position = Other.position;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
int r = Random.Range(0, 100);
if (r == 1 && gameObject.activeInHierarchy)
{
gameObject.SetActive(false);
Invoke(“Reappear”, 2.0f);
}
}
void Reappear()
{
gameObject.SetActive(true);
}
}
The second part was give to me by a nice guy in this forum. Unfortunately that didn’t correspond anymore wich what it’s ask for my project.
Now I wish only the sprite dissapear, and when it do, that the player be teleport at a other location than the “Other.position”.
I try to replace “gameObject.SetActive(false);” by SpriteRenderFalse but Unity dont’t know that.
Last point: I will need a other type of portal, which change the current scene of the game. The player don’t need to be teleport; he is place in every scene of the game. So I just need a change of scene when player tag is collision with game object but again I don’t know how write that.
Thanks to read my message.
Have a nice day.