Spawn Random Objects

Spawn Random Objects only by a horizontal line

Unity 2D Spawn Random Objects only by a horizontal line for desktop or mobile

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

public class MeteoriteMove : MonoBehaviour
{
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
rb.velocity = new Vector2(rb.velocity.x, -0.9f);
}

// Update is called once per frame
void Update()
{
transform.Rotate(Vector3.back * 20f * Time.deltaTime);
rb.velocity = new Vector2(rb.velocity.x, -0.9f);

}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "ResetTag")
{
Destroy(gameObject);
}
}
}

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

public class SpawnMeteorite : MonoBehaviour
{
public GameObject[] enemy;
[SerializeField] public float interval = 10f;
private float timer = 0;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if(timer >= interval)
{
int randomEnemy = Random.Range(0, enemy.Length);
var pos = new Vector3(Random.Range(-4, 4), Random.Range(8,8), Random.Range(10,10));
Instantiate(enemy[randomEnemy], pos, Quaternion.identity);
timer = 0;
}
}
}

Is this Articolo useful? Useful Useless 0 of 0 people say this Articolo is useful.

Saw Vertical

Saw Animation Vertical with Unity 2D

Unity 2D Animation Vertical with Saw Object.

C# CODE

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

public class SawV : MonoBehaviour
{
Rigidbody2D rb;
bool top = true;
bool down = false;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

// Update is called once per frame
void Update()
{
transform.Rotate(Vector3.back * 200 * Time.deltaTime);
if (top)
{
rb.velocity = new Vector2(rb.velocity.x, -4);
}
if (down)
{
rb.velocity = new Vector2(rb.velocity.x, 4);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "TopTag")
{
top = true;
down = false;
}
if (collision.tag == "DownTag")
{
top = false;
down = true;
}
}
}

Is this Articolo useful? Useful Useless 0 of 0 people say this Articolo is useful.

Saw Horizontal

Saw Animation Horizontal with Unity 2D

Unity 2D Animation Horizontal with Saw Object.

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

public class SawH : MonoBehaviour
{
Rigidbody2D rb;
bool left = true;
bool right = false;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

// Update is called once per frame
void Update()
{
transform.Rotate (Vector3.back * 200 * Time.deltaTime);
if(left)
{
rb.velocity = new Vector2(4, rb.velocity.y);
}
if (right)
{
rb.velocity = new Vector2(-4, rb.velocity.y);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "LeftTag")
{
left = true;
right = false;
}
if (collision.tag == "RightTag")
{
left = false;
right = true;
}
}
}

Is this Articolo useful? Useful Useless 0 of 0 people say this Articolo is useful.

Unity 2D Spawn Infinity Star

VIDEO PART NUMBER ONE

Part number 1 Spawn Infinity Stars for Mobile and Desktop.

VIDEO PART NUMBER TWO

Part number 2 Spawn Infinity Stars for Mobile and Desktop.

C# CODE

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

public class SpawnStar : MonoBehaviour
{
public GameObject starObj;
public int maxStars = 100;
// Start is called before the first frame update
void Start()
{
Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
for(int i = 0; i < maxStars; ++i)
{
GameObject star = (GameObject)Instantiate(starObj);
star.transform.position = new Vector2(Random.Range(min.x, max.x), Random.Range(min.y, 40));
star.GetComponent().speed = -(1f * Random.value + 0.5f);
star.transform.parent = transform;
}
}

// Update is called once per frame
void Update()
{

}
}

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

public class StarController1 : MonoBehaviour
{
public float speed = -0.2f;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
Vector2 pos = transform.position;
pos = new Vector2(pos.x, pos.y + speed * Time.deltaTime);
transform.position = pos;
Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
if(transform.position.y < min.y)
{
transform.position = new Vector2(Random.Range(min.x, max.x), max.y);
}
}
}

Is this Articolo useful? Useful Useless 0 of 0 people say this Articolo is useful.

Database Sqlite with javaFX

How to create database and table sqlite with javaFX

How to create Database and Table Sqlite with javaFX

package application;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;

public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
GridPane grid = new GridPane();
Scene scene = new Scene(grid,800,600);
createNewDatabase();
createNewTable();
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Tutorial");
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

public static void createNewDatabase() {
String url = "jdbc:sqlite:src/application/database/test.db";

try (Connection conn = DriverManager.getConnection(url)) {
if (conn != null) {
DatabaseMetaData meta = conn.getMetaData();
System.out.println("A new database has been created.");
}

} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public static void createNewTable() {
// SQLite connection string
String url = "jdbc:sqlite:src/application/database/test.db";

// SQL statement for creating a new table
String sql = "CREATE TABLE IF NOT EXISTS table1 (\n"
+ " id integer PRIMARY KEY,\n"
+ " first_name text NOT NULL,\n"
+ " last_name text NOT NULL,\n"
+ " city text NOT NULL\n"
+ ");";

try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
// create a new table
stmt.execute(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public static void main(String[] args) {
launch(args);
}
}

Is this Articolo useful? Useful Useless 0 of 0 people say this Articolo is useful.