Fulfinsen
Fulfinsen
CC#
Created by Fulfinsen on 9/24/2023 in #help
❔ Score increment
thanks for the info
10 replies
CC#
Created by Fulfinsen on 9/24/2023 in #help
❔ Score increment
I see
10 replies
CC#
Created by Fulfinsen on 9/24/2023 in #help
❔ Score increment
ah, ok
10 replies
CC#
Created by Fulfinsen on 9/24/2023 in #help
❔ Score increment
Block.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Block : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (transform.position.y < -6f)
{
Destroy(gameObject);
}


}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Block : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (transform.position.y < -6f)
{
Destroy(gameObject);
}


}
}
10 replies
CC#
Created by Fulfinsen on 9/24/2023 in #help
❔ Score increment
Player.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour
{
public float moveSpeed;
private Rigidbody2D rb;

// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (touchPos.x < 0)
{
rb.AddForce(Vector2.left * moveSpeed);
}
else
{
rb.AddForce(Vector2.right * moveSpeed);
}
}
else
{
rb.velocity = Vector2.zero;

}
}

void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "block")
{
SceneManager.LoadScene("Game");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour
{
public float moveSpeed;
private Rigidbody2D rb;

// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (touchPos.x < 0)
{
rb.AddForce(Vector2.left * moveSpeed);
}
else
{
rb.AddForce(Vector2.right * moveSpeed);
}
}
else
{
rb.velocity = Vector2.zero;

}
}

void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "block")
{
SceneManager.LoadScene("Game");
}
}
}
10 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
thanks
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
now it works
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
I removed the Rigidbody2D and assigned rb2d as needed
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
yeah, you are right
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
yeah, there is definitely something that I am missing and I don't see it
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
I put a debug.logError to see what is happening and it says that Rigidbody2d is not assigned
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
and it points me at
var absVelX = Mathf.Abs(rb2d.velocity.x);
var absVelX = Mathf.Abs(rb2d.velocity.x);
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
now I am getting an error in unity:
NullReferenceException: Object reference not set to an instance of an object
Player.Update () (at Assets/Scripts/Player.cs:23)
NullReferenceException: Object reference not set to an instance of an object
Player.Update () (at Assets/Scripts/Player.cs:23)
24 replies
CC#
Created by Fulfinsen on 9/21/2023 in #help
❔ 2D player movement
something like this?
private Rigidbody2D rb2d;


void Start()
{
Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
}
private Rigidbody2D rb2d;


void Start()
{
Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
}
24 replies