Question by
unity_yCl73dUSuMVAzg · May 21, 2020 at 10:04 AM ·
c#unity 2d
Instanciated objects work to the left but not to the right,When i instantiate an object it doesnt work
What i mean by this, is the fact that the sprite is instanciated everytime, however, i can only see them if I instancate them while looking to the left: 
Here are my scripts: (I know they are bad) using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement : MonoBehaviour
{
public int moveSpeed = 2;
public int jumpSpeed = 2;
public Rigidbody2D rb;
public int onGround = 2;
public GameObject parent;
void Update()
{
Jump();
Rotate();
}
// Update is called once per frame
void FixedUpdate()
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal") , 0 , 0);
transform.position += movement * Time.fixedDeltaTime * moveSpeed;
}
public void Jump()
{
if (Input.GetButtonDown("Jump") && onGround > 0)
{
onGround--;
rb.AddForce(new Vector2(0f , jumpSpeed), ForceMode2D.Impulse);
}
}
void Rotate()
{
if (Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
if (Input.GetKeyDown("a"))
{
transform.rotation = new Quaternion(0 , 180 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 180 , 0 , 0);
}
if (Input.GetKeyDown("a") && Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
}
}
Shooting:
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform firepoint;
public GameObject bullet;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
BulletCommitShoot();
}
}
public void BulletCommitShoot()
{
Instantiate(bullet , firepoint.position , firepoint.rotation);
}
}
Ground Checking script:
using UnityEngine;
public class CheckGround : MonoBehaviour
{
public Rigidbody2D rb;
GameObject player;
void Start()
{
player = gameObject.transform.parent.gameObject;
}
private void OnCollisionEnter2D(Collision2D collision) {
if (collision.collider.tag == "GTL")
{
player = gameObject.transform.parent.gameObject;
player.GetComponent<Movement>().onGround = 2;
}
}
}
Sorry for having long question.,When i look to the left, the object gets instantiated, however, when i look to the right, it gets instanciated however, it doesn't render. Here are my scripts: (I am a begginer, i know my scripts are bad);
Movement Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public int moveSpeed = 2;
public int jumpSpeed = 2;
public Rigidbody2D rb;
public int onGround = 2;
public GameObject parent;
void Update()
{
Jump();
Rotate();
}
// Update is called once per frame
void FixedUpdate()
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal") , 0 , 0);
transform.position += movement * Time.fixedDeltaTime * moveSpeed;
}
public void Jump()
{
if (Input.GetButtonDown("Jump") && onGround > 0)
{
onGround--;
rb.AddForce(new Vector2(0f , jumpSpeed), ForceMode2D.Impulse);
}
}
void Rotate()
{
if (Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
if (Input.GetKeyDown("a"))
{
transform.rotation = new Quaternion(0 , 180 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 180 , 0 , 0);
}
if (Input.GetKeyDown("a") && Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
}
}
CheckGround Script: (the one that checks if the character is on the ground)
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform firepoint;
public GameObject bullet;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
BulletCommitShoot();
}
}
public void BulletCommitShoot()
{
Instantiate(bullet , firepoint.position , firepoint.rotation);
}
}
Finally, the shooting script:
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform firepoint;
public GameObject bullet;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
BulletCommitShoot();
}
}
public void BulletCommitShoot()
{
Instantiate(bullet , firepoint.position , firepoint.rotation);
}
}
Here are screenshots of my problem: 
I am really sorry for having a long question.
Comment
Your answer