#๐Ÿ–ผ๏ธโ”ƒ2d-tools

1 messages ยท Page 37 of 1

rare parrot
#

why does fire point need to be separate from gun?

still tendon
#

where would the bullet spawn then

rare parrot
#

at the guns location, plus an offset to appear at end of muzzle

ruby karma
#

they mean to say, why can't the fire point move with the gun

still tendon
#

so make the firepoint a child of the gun or??

ruby karma
#

try it ๐Ÿ‘€

still tendon
#

ok

#

didnt work lol

rare parrot
#

show code for fire point

#

and show code for gun

still tendon
#

the gun is just a model

#

it doesnt work lol

#

it just there for looks

rare parrot
#

just have the script run on gun, delete firepoint

still tendon
#

but then some of the code has to change no?

ruby karma
#

I would recommend you to first of all setup VS or VSCode whatever that is to provide autocomplete. Links on how to do that are pinned in #๐Ÿ’ปโ”ƒcode-beginner

still tendon
#

what will vs do

rare parrot
still tendon
#

ill try it now

rare parrot
still tendon
#

it shoots near the legs and it still goes to the right

rare parrot
#

???

still tendon
#

the bullets spawn near the legs

#

and the direction of the bullets still the same

rare parrot
#

wheres the center of the gun gameobject

still tendon
#

uh

#

no idea

rare parrot
#

click it in the heirarchy window

#

press w to select move tool if not already so

#

where the y and x vectors meet should be center of gameobject

rain ingot
#
public Sprite[] imageList = new Sprite[] {
        Sprite red = Resources.Load ("Assets/Assets/GFX/RED"),
        Sprite blue = Resources.Load ("Assets/Assets/GFX/BLUE"),
        Sprite green = Resources.Load ("Assets/Assets/GFX/GREEN");
    };
#

is dis right

still tendon
rare parrot
#

where the red and green arrows meet

still tendon
rare parrot
#

is that the center of the gun?

still tendon
#

yes thats the gun chosen

rain ingot
#

ok

still tendon
#

in that photo the gun itself was selected

rare parrot
#

ok

still tendon
#

not any of the cubes'

rare parrot
#

huh

still tendon
#

thats the gun

#

its an empty object

#

with cube children

rare parrot
#

why the cubes

still tendon
#

to make the gun??

#

it didnt make a sprite lol

#

i*

rare parrot
#

the gun should be one gameobject

#

with a spriterenderer component

still tendon
#

it wouldve been much easier but i made the gun when i was like 2 days into it

#

yes i know

#

but its already made

#

doyou want me to delete it?

rare parrot
#

for best practices, yes

still tendon
#

ok hold on

rare parrot
#

it doesnt take long

still tendon
#

i hvae to go eat first

#

ill be right back

rare parrot
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetScript : MonoBehaviour
{
    int Color = 0;
    public Sprite[] image;

    public void onClick() {
        Color = Random.Range(0, 2);
        Debug.Log(Color);
    }
}```
#

@rain ingot

#

look in the inspector window, you should be able to set size of array and assign the sprites there

rain ingot
#

for onclick i need to add a button?

rare parrot
#

yes

rain ingot
#

yes

#

ik

still tendon
#

hello

rain ingot
#

doest log

#

ik how to od

rare parrot
#

ok

rain ingot
#

it doesnt log

rare parrot
#

did you drag the gameobject with the script into onclick event

rain ingot
#

yes

rare parrot
#

did you set the function to onClick from TargetScript class

#

ok

#

is the button a child of a canvas

rain ingot
#

no

still tendon
#

alright ive done it

rain ingot
#

it shoud be

still tendon
#

its a sprite now

rare parrot
#

create a canvas ui object, put button as child under the canvas

still tendon
#

do i place the script

rare parrot
still tendon
#

ok ill try it

rare parrot
#

place it onto the gun

still tendon
#

it still shoots to the right

#

and now it doesnt even shoot from the gun

#

shoots from here

rare parrot
#

offset the position

still tendon
#

??

#

what

rare parrot
#

when you call instantiate, add new Vector3(x,y,z) to transform.position

still tendon
#

mhm def understood that

rare parrot
#

instantiate(bulletPrefab, transform.position + new Vector3(0,0,0), transform.rotation);

#

adjust x,y,z values of new Vector3

still tendon
#

to what numbers

rare parrot
#

find out through trial and error

still tendon
#

whats supposed to be happening with this piece of code exactly?

#

so i can understand what im even tyring to do

rare parrot
#

adds the x,y,z values to the position

#

of where it spawns

still tendon
#

u mean moves this?

rare parrot
#

no

#

the center stays the same

#

when you spawn the bullet, it references that center

#

the code adds to the position of the center

#

hence offset

still tendon
#

aha

rare parrot
#

if you want to change the center to be at the end of the gun, you have to change the pivot position in sprite editor

still tendon
#

ok so i got the numbers

#

theyre decimals tho

rare parrot
#

thats fine

still tendon
#

1.75 to 2.11

#

x

#

0 to 0.25

#

y

#

thats it

rare parrot
#

nvm you shouldnt add offset to position, thats bad practice

still tendon
#

ok

#

so what do i do

rare parrot
#

click on the sprite in the project window, look to inspector

#

should see this

still tendon
#

do i return the code to what it used to be

rare parrot
#

no

still tendon
#

ok

rare parrot
#

just remove + new Vector3

#

dont need to offset if the center is at the end of gun

still tendon
#

capital i?

rare parrot
#

yes

#

Instantiate, not instantiate

still tendon
#

do i press sprite editor

rare parrot
#

yes

still tendon
#

ok now what

rare parrot
#

change pivot from center to customized

still tendon
#

ight

rare parrot
#

play around with values

#

of custom pivot

still tendon
#

??

#

yeah and to what numbers exactly

#

what does itmove the sprite or the gun

rare parrot
#

trial and error until pivot is at the end of the gun

#

its moves the pivot

#

it does not move the sprite

#

or the gun

still tendon
#

ohh this thing

rare parrot
#

yes

still tendon
#

ok ok

rare parrot
#

move blue circle to end of gun

frozen anvil
#

I have a character in a multiplayer game. I want to be able to change the color of the character but certain parts should always be the same color. So what's the best way to change the color on some parts without having to make lots of different sprites and animations?

still tendon
#

or in the middle

rare parrot
#

whatever u want

still tendon
#

alright

#

its in the middle

#

at the end

#

now its gonna spawn from there correct?

rare parrot
#

yes

still tendon
#

but it still looks the same in scene?

rain ingot
#

i did the canvas thing still doesnt work

rare parrot
still tendon
#

ah ok

#

alright

#

it works

#

but the direction is still fucked

#

shoots right both ways

rare parrot
still tendon
#

just like always

rain ingot
rare parrot
still tendon
#

me and the enemy bot are facing this problem by the way the bot still has a firepoint

rare parrot
still tendon
still tendon
rare parrot
frozen anvil
rain ingot
still tendon
#

matches*

rare parrot
frozen anvil
#

yeah I guess that works

#

thx

rare parrot
# rain ingot wdym

run the game, click eventsystem in hierarchy window, hover mouse over button, look in inspector window for raycastable target

rare parrot
#

not left mouse button

still tendon
#

what

#

im trying to make the center face left when i turn left

#

is that what the velocity does

rare parrot
#

velocity of bullet makes would make it move in the positive or negative direction

rain ingot
still tendon
#

ohh

#

how do i do that

#

and if statment?

#

an*

#

i tried to do this but i have no idea how i can write it

rare parrot
#

if left input, multiply bullet velocity by -1, if right input, reset bullet velocity to original value

rare parrot
still tendon
#

how would i identify left and right

rare parrot
rain ingot
#

yes

still tendon
#

how do i tell the computer that

#

left == -1?

rain ingot
still tendon
#

left = -1**

rare parrot
still tendon
rain ingot
#

not sure

still tendon
#

oh

#

i dont think so

rain ingot
still tendon
#

but i aswell am not sure

rare parrot
# still tendon left = -1**

right should just be the original value of bullet velocity, left should be negative value of bullet velocity

still tendon
#

is the spped veloctiy?

#

this is a script for the bullet itself

rare parrot
#

yes

still tendon
#

so 10 and -10

#

do i need to add an f or not

rare parrot
#

yes

#

no

still tendon
#

10f-10f

#

ok

rare parrot
#

10 is an int, not a float

#

its unnecessary

still tendon
#

so now i need to tell it that whne i press a it changes it to negative and when i press d it changes back to positive?

rare parrot
rain ingot
#

yes

rare parrot
#

and this is the eventsystem info?

rain ingot
#

yes

still tendon
#

alright ill try my best

#

if statement right?

rain ingot
still tendon
rare parrot
#

nvm that works

still tendon
#

how exacly do i tell it to change

#

i need to call the bullet script dont i

rare parrot
still tendon
#

afk

rain ingot
rare parrot
#

current raycast isnt the button when you hover over it?

rain ingot
#

nope

rare parrot
rain ingot
#

target is the button

rare parrot
#

did you configure canvas component

rain ingot
rare parrot
rain ingot
rare parrot
#

drag main camera into render camera

rain ingot
#

ok

#

stilll current raycast no work

rare parrot
#

change render mode to screen space, then back to world space

#

to automatically fit canvas to screen then be able to move buttons to gameobject position in world space

rain ingot
#

ok

#

still current raycast no work

rare parrot
#

where is the button in the scene

rain ingot
#

child of canvas

rare parrot
#

not hierarchy, the scene view

rain ingot
#

in midle of my camera

rare parrot
#

button is a raycast target?

rain ingot
#

i have my sprite as a child of my button

rare parrot
#

why are the button and button sprite separate gameobjects?

rain ingot
#

idk

#

shoud i put them in one

rare parrot
#

delete sprite gameobject, add image component to button

rain ingot
#

now the button hitbox is too big

rare parrot
#

change the width and height of the rect transform

rain ingot
#

it changes the image troo

rare parrot
#

the width and height of rect trransform should be the same ratio as the image dimensions

still tendon
#

is that wrong

#

im writing it in the weapon script

rare parrot
# still tendon im not

if youre writing it player controller (which u should), then you'll need to reference the bullet script to access the bullet speed variable

still tendon
#

is this wrong

rain ingot
#

the random only gives me 0 and 1

#

when range is 0, 2

snow willow
rare parrot
rare parrot
still tendon
#

ok i have two scripts for the movement sinc ei followed brackeys tutroial

rain ingot
#

now i need to do the sprite swiching

rare parrot
#

you already have input code in player controller

still tendon
#

one is this

#

and the other is just a shit ton of code

#

and more

still tendon
#

when i only put the character controller and attempted to move

#

it only changed my direction

#

so i think i have to put the cod einto character controller

#

?

rare parrot
#

nvm, just keep it in weapon script

still tendon
#

ok lol

#

how do i refrence the bullet script i forgot

rare parrot
#

get the script component from the referenced gameobject

still tendon
#

can u type it

rain ingot
#

now how do i load the images form array to the image component

still tendon
#

like this but instead of rb2d its bullet?

rare parrot
still tendon
#

and then speed

#

bullet = GetComponent<speed>();

#

?

#

and

#

public Bullet bullet;

#

?

rare parrot
#

declare public GameObject bullet;

still tendon
rare parrot
#

oh, it looks like you already reference the bullet

#

bulletPrefab

still tendon
#

i refrence its prefab not its script

#

is it the same

rare parrot
#

you reference the script from the prefab

rain ingot
still tendon
#

the script is called bullet aswell as the bullet itself

#

does that cause confusion

rare parrot
#

the script that has the bullet speed variable isnt called Weapon?

still tendon
#

the script im trying to call isnt called weapon yes

#

the script im currently typing in is weapon

rare parrot
#

which script has bullet speed variable

still tendon
#

the bullet script

rare parrot
still tendon
rain ingot
#

gameObject.GetComponent<Image>();

#

?

still tendon
#

?

rare parrot
# still tendon

reference the bullet speed variable by assigning bullet gameobjectbullet.GetComponent<Bullet>();

#

from weapon script

#

i recommend you rename bullet gameobject to bulletScript in weapon script

still tendon
#

in void update correct?

rare parrot
#

assign it in start()

still tendon
#

ok

#

alright

#

now i can use the f statements right?

#

if*

rain ingot
#
image = Target.GetComponent<Image>()
#

?

rare parrot
#

write if statements in update()

still tendon
#

if (input.getbuttondown("a"))

#

yes i know

#

speed = -10

#

else (input.getbuttondown("d"))

rare parrot
#

reference bullet speed by bulletScript.speed

still tendon
#

speed = 10

#

oh ok

#

bulletScript.speed = 10 or -10

#

yes

#

?

rare parrot
rain ingot
#

idk

rare parrot
#

run it

rain ingot
#

Assets\TargetScript.cs(11,17): error CS0103: The name 'Target' does not exist in the current context

#

Assets\TargetScript.cs(11,37): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)

still tendon
#

should probably delete "left" and "right"

#

or i can be epic and replace 10 and -10 with left and right

#

nah too much work

#

alright i deleted them

rare parrot
still tendon
#

ok

still tendon
#

theres no such thing as bulletspeed in the script tho?

still tendon
#

or is simply saying bullet going to refrence the script

rain ingot
#

image = Target.GetComponent<Image>();

#

Assets\TargetScript.cs(11,41): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)

rare parrot
still tendon
#

theres no speed in weapon but there is speed in bullet

rare parrot
#

delete right

rain ingot
#

thats the error

still tendon
#

ah ok

#

does that mean i have to type +bulletSpeed then

rare parrot
still tendon
#

oh

rare parrot
#

just initialize bulletSpeed to 10

rain ingot
#

switch sprite from a array

still tendon
rare parrot
still tendon
#

do i save and hit play now

still tendon
rare parrot
rare parrot
still tendon
#

ok sorry

#

what

#

why does it expect a ; in else???

#

40 is the end of the code

rare parrot
still tendon
rare parrot
rare parrot
still tendon
#

else if

rare parrot
#

no

still tendon
#

or just a different if

rare parrot
#

just if() and if()

still tendon
#

ok

rare parrot
#

is speed a public variable

rain ingot
#

Assets\TargetScript.cs(14,40): error CS0119: 'Sprite' is a type, which is not valid in the given context

rare parrot
#

is this script in the button

rain ingot
#

yes

rare parrot
#

show code

rain ingot
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetScript : MonoBehaviour
{
    int Color = 0;
    public Sprite[] image;


    public void onClick() {
        Color = Random.Range(0, 3);
        Debug.Log(Color);
        GetComponent<Image>().sprite = Sprite[Color];   
        }

}
rare parrot
#

should be GetComponent<Image>().sprite = image[Color];

#

not GetComponent<Image>().sprite = Sprite[Color];

rain ingot
#

but my arrays name is Sprite

rare parrot
#

your array name is image

rain ingot
#

oof

rare parrot
#

you declare image as a Sprite array

rain ingot
#

Assets\TargetScript.cs(14,22): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)

rare parrot
#

show code

rain ingot
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetScript : MonoBehaviour
{
    int Color = 0;
    public Sprite[] image;


    public void onClick() {
        Color = Random.Range(0, 3);
        Debug.Log(Color);
        GetComponent<Image>().sprite = image[Color];   
        }

}
rare parrot
#

add using UnityEngine.UI; namespace

rain ingot
#

yay

#

no error

still tendon
#

and i styill gotta afk

#

so wait a bit

#

@rare parrot

#

hello?

rare parrot
#

?

still tendon
#

im back

#

bulletspeed was not public

rare parrot
#

make it public

still tendon
#

the error still appears tho

#

i made it public and saved

#

its still here

#

even in th ebullet script itsd public

#

i think its talking about bulletScript

#

idk

rare parrot
#

bulletScript gets assigned the reference to Bullet script from bullet gameobejct

still tendon
rare parrot
#

is the class public

still tendon
#

yes'

rare parrot
#

show animator window

still tendon
#

hold up

#

i thought homie was flying

rare parrot
still tendon
#

i setup a blend tree

#

i dont have any up/down animations so i want to use the left running animation when going down, IF last facing direction was left

#

and the same thing for the right

rare parrot
# still tendon

did you assign the bulletScript reference in the inspector window

still tendon
#

???

#

what

#

drop the script on the object

#

it doesnt show

rare parrot
#

nvm

rare parrot
# still tendon

not familiar with blend trees, why use a blend tree as opposed to a finite state machine?

still tendon
#

i would have the same error with a state machine

#

i just need some way in the code to recognize the last direction

#

and default to the right animation

rare parrot
#

it recognizes current direction by use horizontal and vertical input right

still tendon
#

yeah

rare parrot
#

can u store current input in a variable for previous input to recognize last direction

still tendon
#

i guess

rare parrot
#

not weapon script

still tendon
#

oh

#

wait

#

bullet script in the gun??

rare parrot
#

bullet script on the bullet

still tendon
#

ther eit is

rare parrot
#

that on the gun?

still tendon
#

np

#

no

#

on bullet

rare parrot
#

write bulletScript = bulletPrefab.GetComponent<Bullet>();

#

in weapon script

#

in start()

still tendon
#

the error says the problem is within here

rare parrot
#

show code

still tendon
#

it says 13 and 24

#

fuck

#

afk

#

busy day today

rare parrot
#

declare public Bullet bulletScript, not public GameObject bulletScript

still tendon
#

back

#

lets goo theyre gone

#

@rare parrot

#

the only error left is just a triangle error

#

ive been ignoring it since like day 3

#

yo it wont let me choose anything'

#

@rare parrot

#

i can put the bullet prefab in there

#

just not the script

rare parrot
#

does the bullet prefab work

still tendon
#

hes

#

yes

#

input button a isnt an input

#

lol

#

should i put horizontal instead or??

#

in the player movement a and d are both calle dhorizontal though

#

hm

#

ill just make ne inputs lol

#

new'

#

IT WORKSSS

#

@rare parrot THANK YOU SO MUCH FOR PUTTING THRU MY BULLSHIT

rare parrot
#

np

still tendon
#

o shit wait how do i do this to my enemy tho

#

bots dont press a or d

#

fuckkkkkkkkkk

rare parrot
#

where code is for move bot left or move bot right, same applies

still tendon
#

what

#

bot doesnt go left or right it follows me

#

three enemy scripts

#

well two

#

enemy gfx isnt being used

#

theres like no code that tells it to face left or right@rare parrot

#

thats the enemyAi

#

this is what makes it shoot

#

it shoots non stop even if im not in view

rare parrot
still tendon
rare parrot
#

??

still tendon
#

oh

#

lmao oops

rare parrot
#

the enemy is suspended in air?

still tendon
#

its a flying enemy

rare parrot
#

and you want the enemy to face towards the player?

still tendon
#

supposed to be like a robot turret thing

#

yes

#

currently it isnt

#

but when i press play it does

#

not really right at me but like left or right

knotty barn
still tendon
#

what

#

uh dumb it down?

#

behaviour as in which way theyre going?

#

liek detect if theyre going - or +?

knotty barn
#

Move the input collection to a separate script

still tendon
#

icluding fire1?

#

including*

knotty barn
#

PlayerInput listens for input devices and AIInput generates them based on AI decisions

still tendon
#

what

knotty barn
#

Yea fire could just be a fire bool

rare parrot
still tendon
#

in enemy ai script correct?

rare parrot
#

player is reference to player gameobject

#

yes

still tendon
#

and unfreeze rotation?

rare parrot
#

yes

still tendon
#

hm might fuck up things

#

since when i unfreeze it

#

the moment i touch it it breaks the bot

rare parrot
#

how?

still tendon
#

idk i can show u in screen sahre tho

#

oh wait

#

it doesnt do it anymore

#

it used to go crazy all around the map

#

and some of the time it get touched and just goes flying

#

i mean it still does go flying but not as bad

#

since after i make it go flying it stops moving

#

but now it doesnt

#

ill try the code

#

it already has atarget for player

#

do i just put target

rare parrot
#

sure

still tendon
#

oh what in the fuck

#

it uh

#

works?

rare parrot
#

freeze x and y rotation

#

leave z rotation unfrozen

still tendon
#

doesnt exist

#

do i give it a 3d rigidbody

rare parrot
#

sure

still tendon
rare parrot
#

change to 3d collider

still tendon
#

how will it hi tme

#

hit me

rare parrot
#

nvm

fickle arrow
#

doesnt it work just by adding a 2d rigidbody?

still tendon
#

rotation for x and y doesnt exist in 2d

#

it decided to go to the core of the earth

#

it also still looked at me without its sprite

rare parrot
#

the suggested LookAt() but it requires Vector3 to be passed

still tendon
#

with rigidbody 3d too?

rare parrot
#

just google how to rotate object towards player 2d unity

still tendon
#

ok

#

after doing that

#

how do i make it shoot out of its mouth

rare parrot
#

instantiate enemy projectile at transform.position and transform.rotation

#

offset position if u want by changing pivot of enemy sprite

still tendon
#

enemy projectile is also the same bullet

rare parrot
#

thats fine

#

nvm

#

your bullet script has player code in it

#

just create a new prefab, assign it the same sprite

still tendon
#

perfect

still tendon
#

do i copy everything from the original bullet

rare parrot
#

just the code that moves it

still tendon
#

but that causes the entity to die tho

#

theres nothing for the player??

#

thats the entire script for the bullet btw

#

nothing else nothing less

rare parrot
#

i mean create a new bullet prefab for the enemy

#

create new script, should only contain code to move it

still tendon
#

move what

#

the bullet?

rare parrot
#

the enemy bullet

#

collision should be detected by tags

still tendon
#

so basically remove what i crossed out right?

rare parrot
#

that code is for damaging the player?

still tendon
still tendon
rare parrot
#

the enemy bullet should not damage itself

still tendon
#

it doesnt

#

it doesnt have the entityhealth script

#

only entites with that script get damaged then deleted

rare parrot
still tendon
#

yes

#

the corsse dout

rare parrot
still tendon
#

sorry

#

got distracted

#

the crossed out has the entityhealth called in it

#

this is the entityhealth

#

here its called

rare parrot
#

so what is the issue

still tendon
#

if i delete that part

#

the bullet wont do any damage

rare parrot
#

ok so dont

still tendon
#

itll immediatley one shot everything

#

and since i crossed out destory aswell

#

it wont even one shot them

#

it doesnt do anything

#

so i literally cant delete anything from bullet lol

#

nothing involves the player

#

neither here

#

btoh can be applied to absolutley anything

rare parrot
#

so what is the issue again

still tendon
#

u told me to make a new bullet and delete stuff of it

#

i cant delete anything or i break the bullet

rare parrot
#

yea, i said so dont

#

keep it as it is

still tendon
#

oh but hwy make a new tho?

#

whats the difference

rare parrot
#

you said it was deleting the turret right?

still tendon
#

what

#

what was deleting it??

rare parrot
#

nvm i misunderstood

still tendon
#

oh ok

#

what do i do

rare parrot
#

instantiate the bullet prefab from turret\

still tendon
#

in what script

rare parrot
#

in whichever script u want to control enemy fire

still tendon
#

in enemyshoot?

rare parrot
#

sure

still tendon
#

its the script that allows it to shoot

#

replace it with transform instead of firepoint yes?

rare parrot
#

yes

#

and delete firepoint

still tendon
#

ok done

#

the firerate is second or?

#

i dont really understand it

#

i yoinked the script lol

rare parrot
still tendon
#

so if i add more numbers

#

thats how many second it would take to shoot?

rare parrot
#

as many numbers as seconds

#

1 = 1 second

#

for practical purposes

still tendon
#

ok wait i gotta brb

rain ingot
#
Vector2 newPos;
        newPos.x = Random.Range(1920, 0);
        newPos.y = Random.Range(1080, 0);
        Target.transform.position = newPos;
#

Assets\TargetScript.cs(23,9): error CS0103: The name 'Target' does not exist in the current context

#

why does it not work

snow willow
rain ingot
#

how do i do like on click my target moves rando,ly on the screen

snow willow
#

That code would work but you need to actually have a variable called Target

rain ingot
#

how

snow willow
#

How do you declare a variable?

rain ingot
#

how do i declare a variable thats a gameobject

snow willow
#

?

#

Looks like you only care about the Transform so why not just use Transform

#

But if you want a different type, just use that type instead of Transform

rain ingot
#

yeah

#

how do i do dat

#

?

marsh lion
rain ingot
#

Assets\TargetScript.cs(23,16): error CS1061: 'GameObject' does not contain a definition for 'Transform' and no accessible extension method 'Transform' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

marsh lion
#

Oh.

#

Transform variablename

marsh lion
rain ingot
#
        Vector2 newPos;
        newPos.x = Random.Range(0, 1920);
        newPos.y = Random.Range(0, 1080);
        Transform.Target = newPos;
#

1
UnityEngine.Debug:Log (object)
TargetScript:onClick () (at Assets/TargetScript.cs:18)
UnityEngine.EventSystems.EventSystem:Update () (at C:/Program Files/Unity/Hub/Editor/2019.4.21f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

still tendon
#

@rare parrot hello im back

rain ingot
#

soemone pls halp

still tendon
#

what

#

gtg

still tendon
#

Is there any way to make it instead of on keypress into a on button press. I have a button in my game already and it works fine but how do I make this line of code into a script that will let me access it through my ingame button?

#

It works with load menu but no idea how to make it pause the game

#

resume doesn't work, I tried

#

unless i coud make a new void thing

#

nvm

#

made void pause into public void pause and i got function pause working

#

all works

#

Why when I ask people, I always find out whats the problem

#

weird

snow willow
#

It's magic

still tendon
#

ikr

snow willow
#

Also you need to think about the problem in a certain way to formulate a question properly

#

Gets the juices flowing

snow willow
#

You want Target.transform.position = newPos;

rain ingot
#

@snow willow

#

someone pls help

snow willow
rain ingot
#

oh

#

now how do i clamp it to my screen

rain ingot
#

someone pls halp

rain ingot
#

how do i make dis a float

newPos.x = Random.Range(0, 0.5);
        newPos.y = Random.Range(0, 0.5);
hard crag
#

newPos.x = Random.Range(0, 0.5f);

rain ingot
#
        Vector2 newPos;
        newPos.x = Random.Range(0, 0.1f);
        newPos.y = Random.Range(0, 0.1f);
        Target.transform.position = newPos;
#

returns

#

same position allways

snow willow
#

0 and 0.1 are pretty close to each other

#

You won't get much variation

still tendon
#

help

#

my enemy is spawning bullets inside of itself

#

so it keeps killling itself

#

and now my player does it too

#

it was all going fine till i started it up

snow willow
still tendon
#

wont that ignore the enemy aswell?

#

this never happend nor did it happen befor ei closed unity

snow willow
#

No it makes two specific Colliders ignore each other

still tendon
#

alright how does it work

still tendon
#

Physics2D.IgnoreCollision(collider1, collider2)?

snow willow
#

Yes

still tendon
#

oh nice lmao i guessed it

#

where do i put the code

#

in which script

snow willow
#

When you spawn the bullet

still tendon
#

bullet script?

#

ok so bullet script

#

def bullet script

snow willow
#

No

#

Wait what

#

I'm confused

still tendon
#

?

snow willow
#

It should be in the script that spawns the bullet

#

Not the bullet script

still tendon
#

this script spawns the bullet???

#

the bullet script is what spawns it??

#

oh wait nvm

snow willow
#

That's the example code you showed right

still tendon
#

im dumb

#

it isnt in bullet script

#

its in weaponj script

snow willow
#

Yeah

still tendon
#

fire1

snow willow
#

That makes sense

still tendon
#

do i need to change anything

#

Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), GetComponent<Collider2D>());

#

player.circlecollidr2d?

snow willow
#

You need to give it your player's Collider and the bullets Collider

still tendon
#

bullet.capsulecollider2d?

snow willow
#

You can just use Collider2D you don't need to say the specific type

still tendon
#

Physics2D.IgnoreCollision(bullet.GetComponent<Bullet.CpasuleCollider2D>(), GetComponent<Player.CapsuleCollider2D>());

snow willow
#

But you do need to use GetComponent

still tendon
#

I have two colliders for player tho

#

so i can crouch

snow willow
#

You'll need to call it for both of them then

still tendon
#

how

#

another get component?

snow willow
#

Call ignore collision twice

still tendon
#

oh

#

what about the 2nd option

#

also bullet?

#

yeah that makes sense

#

ok but uh

#

the enemy still fucked

#

it shoots inside of itself

#

when the pivot is infront of it

#

it doesnt shoot there

#

i have a script telling it spawn bullet there

#

but wait

#

if i do it for the enemy too

#

i wont be able to shoot it

snow willow
#

IgnoreCollision only works for the specific two Colliders you give it

#

You only want to call it for a bullet and the entity that fired the bullet

#

They will still collide with everything else

still tendon
#

so it doesnt work on the entire script

#

my robot enemy does this jiggly thing everytime he shoot sis that normal

#

only when he faces right

#

@snow willow

distant urchin
#

Hi, I'm a beginner in uniti, I have a problem, my character, when he collides with a wall, everything is trying to enter it exactly how to fix it in a 2D world

still tendon
#

what do u mean

#

what do u mean by everything is trying to enter it?

distant urchin
#

When colliding with an object, the character stops but still tries to enter the ngo but is pushed out

snow willow
# still tendon

Why are you ignoring collisions for both player and enemy there

still tendon
#

where then

snow willow
#

Should just be one or the other depending on who is shooting it

still tendon
#

enemyshoot and weapon

#

one is for the the bot and one for th player

#

do i put each in those

#

@snow willow

distant urchin
still tendon
#

uh what exaclty is happening in the picture?

#

is it not supposed to be standing inside of it?

distant urchin
#

so let me make a gif)

still tendon
#

answer

#

is it not supposed ot be inside the object?

#

to*

distant urchin
#

I don't know how to make the object harder

still tendon
#

harder??

#

what do you mean by harder

distant urchin
#

so that you cannot pass with proper acceleration

still tendon
#

do you want the player inside it or outside the object

distant urchin
#

outside

still tendon
#

collider problem

#

either player or the object itself

distant urchin
still tendon
#

fix the collider

#

make sure it covers the object

distant urchin
still tendon
#

check the player

#

collider might not be covering the sprite

distant urchin
still tendon
#

tf

distant urchin
still tendon
#

tf = the fuck

distant urchin
#

tf

still tendon
#

yeah send a video please

distant urchin
#

yes 5 minutes

distant urchin
still tendon
#

ohh its a top down

#

yeah sorry no clue how top down works

distant urchin
still tendon
#

basically a 2d character only moves left to right if it wants to move up it jumps

#

if u dont know how watch brackeys 2d movement tutorial

#

he also has a top down tutroial

#

if u want

distant urchin
#

Okay, I'll go and take a look

light elk
#

does anyone know that if 2D extras comes with unity or u have to install it?

snow willow
light elk
#

is it?

#

hmm

snow willow
#

If not, everything is available in the package manager

light elk
#

i checked not there

#

i may have missed it

#

using unity 2019

#

maybe its on 202

#

anyways i installed it manually

#

its on preview only not verified

snow willow
#

Yeah some packages are preview packages

light elk
#

yeah i need that to make animated tiles

#

hope no major issues

strange echo
#

What would be the best way to go about making a chess board? My knowledge of unity is very limited, so I'm not even sure if this is a project that I should work on quite yet.

snow willow
#

It's not super beginner friendly

strange echo
#

yeah, thought so

snow willow
#

Maybe start with tic tac toe

#

Then checkers

#

Then chess lol

#

Maybe throw connect 4 in there haha

strange echo
#

I already did tic tac toe

snow willow
#

Ah ok good

strange echo
#

That was fairly simple

#

that was my first project on unity

lament oxide
#

So I am having a weird issue on this asteroids clone I am making, really it's just to learn a bit about how to approach 2D games with Unity...
The problem is that the script that checks whether the players bullet collided with the gameobject or not is destroyed I cannot simply store the amount of asteroids on that gameobject, I must pass it to another script that holds all of the games information for score, lives and the remaining objects in the scene. This script is attached to the scenes camera.

Lots of stuff spawns when I am instantiating more than 1 or 2 new objects.

Asteroid code

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("playerBullet"))
        {
            if (this.gameObject.CompareTag("largeAsteroid"))
            {
                SpawnAsteroids(mediumAsteroid, 2);
                GameManager.playerScore += 30; //add 30 to player score
            }
            else if (this.gameObject.CompareTag("mediumAsteroid"))
            {
                SpawnAsteroids(smallAsteroid, 2);
                GameManager.playerScore += 15; //add 15 to player score
            }
            else if (this.gameObject.CompareTag("smallAsteroid"))
            {
                gm.UpdateNumberOfAsteroids(-1);
                GameManager.playerScore += 5; //add 5 to player score
            }
            Destroy(other.gameObject); //destroy the bullet
            Destroy(this.gameObject); //destroy the asteroid
            gm.playAsteroidSound();
        }
    }


void SpawnAsteroids(GameObject asteroidType, int spawnAmount) 
    {

        if (spawnAmount != 0)
        {
            gm.UpdateNumberOfAsteroids(spawnAmount - 1);
            for (int i = 0; i < spawnAmount; i++)
            {
                Instantiate(asteroidType, transform.position, transform.rotation);
            }
        }
    }
lament oxide
#

I have a feeling that this could be due to instantiating many prefab objects at the same time, but I don't know how else to do this.

rain ingot
#

how do i spawn gameobjects and then remove them

timid kettle
#

I'm trying to implement the ability to climb on the ladder.
The problem I have is when the player gets to the platform he get stuck.
I tried to ignore collision with the ladder and platform layers and it worked fine, but when I'm on top of the ladder (on the platform) I can't go back down the ladder.
Any idea how can I solve this issue?

fast siren
#

to respawn cant you just do scenemanage.loadscene("your scene"); to every enemy or thing you want to touch and die to respawn? and before you use scenemanage you have to import Unity.SceneManager

fast siren
lament oxide
#

Okay deleted last messages due to some confusion, I understand now... You could just extend the collider beyond the platform, and then only let the player down when he presses S or something

fast siren
#

something like that

#

i just started a couple days ago so im not very good at unity c# Unity

lament oxide
#

You could ignore collisions only when the player is going down the ladder... Or transform their position through the platform allowing them to jump down too

#

Also respawn wise you could reload the scene, but another option is just to instantiate a player prefab to a set location, and reset necessary variables such as health.

#

Okay last time I'll say stuff, and this is literally just because I had this problem...
If you are spawning objects and removing them, instantiating will work. But if it's spawning the same object many times then look into object pooling, it'll save a headache in the long term :)

idle wing
#
    {
        if(collision.transform.tag == "Enemy")
        {
            collision.transform.GetComponent<AIShipController>().Damage(LaserDamage);
        }
    }```
#

Im having issues with this, it doesnt collide with the object, both objects have ridgidbodies and colliders

lament oxide
#

collision.gameObject.CompareTag("Enemy")

#

For a start :)

idle wing
#

Thanks, but that doesn't fix my issue

lament oxide
#

So are you trying to push the enemy back or just damage them?

idle wing
#

I'm tryna damage them

#
    {
        Health =- Damage;
        Debug.Log("Hit" + Health);
    }```
#

heres the damage script on the enemyt

lament oxide
#

If I understand correctly, you have your script to check collisions on the enemy, then you update that damage to another script? Sorry I just want to understand the aims of it a bit more

#

I will try make something in a few minutes though, on phone currently

idle wing
#

I have a transform that when it collides with the enemie grabs the enemy script and tells it how much damage to apply

#

but they aint colliding

pale heart
#

hi. i dont know how to check if the player touch the ground. do someone know?

fast siren
#

sure so do you want to just hit the ground or do you want to make something happen once your player touches the ground

pale heart
#

just to make sure if he is on the ground or not

fast siren
#

you would need a box colllider 2d on the platform(ground)

#

you could just use debug log

#

and check the console

pale heart
#

ok

#

thank you very much

fast siren
#

np

#

i didnt really do much ๐Ÿ˜…

lament oxide
# idle wing but they aint colliding

Unsure if this will work, too lazy to build a scene tbh.... This will at least confirm if they are colliding as I have no clue if the way you were applying damage works or not, I have never tried it that way. An alternative is to use "OnTriggerEnter2D" and set the colliders type to a trigger, it's a little checkbox in the inspector.

private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.CompareTag("Enemy")
        {
            Debug.Log("Enemy has been shot")
            private int LaserDamage = 1;
            
            Debug.Log("Laser Damage: " LaserDamage)
            Damage(LaserDamage)
        }
    }
    
    public void Damage(int Damage)
    {
        Health =- Damage;
        Debug.Log("Hit" + Health);
    }
idle wing
#

Thats baso what i just done?

lament oxide
#

With debug logs to show you if they are colliding in inspector, and as I said, unsure if the way you were calling your Damage function and grabbing player health works or not. Also you could use trigger areas

#

Just to make sure, you have set the Enemy tag on your Enemy game object?

agile atlas
#

does anyone know how to move a sprite that has been created with: public Sprite Album;?

idle wing
#

thanks for the help

snow willow
rain ingot
#

can someone help make my instance as a child

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

public class SpawnerScript : MonoBehaviour {
    public GameObject NPC;
    public GameObject Canvas;
    public int howMany;

    void Start() {
        spawn();
    }

    public void spawn() {
        int Timer = 0;
        for(Timer = 0; Timer < howMany; Timer++) {
            Instantiate(NPC);
        }
    }

    public void remove() {
        GameObject.Destroy(NPC.gameObject);
    }

}
agile atlas
snow willow
#

If you pass the parent transform into Instantiate, it will become the parent of the new object

rain ingot
#

uhhhhh

snow willow
agile atlas
#

thanks

#

is whatever the sprite?

snow willow
#

Use this instead:

rain ingot
#

ok

#

Instantiate(NPC, Canvas.transform);

#

like dat

#

?

snow willow
#

Sure, if you want the NPC to be a child of the canvas

rain ingot
#

ok

agile atlas
#

Album.transform.parent = AlbumImg;

#

it says I can't convert type sprite to transform

snow willow
#

you can only set another transform as the parent

agile atlas
#

but I don't know how to set the transform of a sprite

#

I thought I needed a gameobject

snow willow
#

Sounds like AlbumImg is a Sprite, which is just a file asset in your project

#

so it doesn't make sense

snow willow
agile atlas
#

public GameObject Album;
public Sprite AlbumImg;

#

Album.transform.parent = AlbumImg;

#

my goal is to transform.position = new Vector2(2,5);

snow willow
#

That's like trying to set the parent of the album to an image file on your computer

#

Sprite is not an actual part of a GameObject in the world, it's just an image file

snow willow
agile atlas
#

but then there is no img

snow willow
#

I don't understand

#

Are you trying to figure out how to display your image in the game?

agile atlas
#

I'm trying to create sprites with code so I don't have to move everything into the hierarchy

#

and I want to parent with code so I don't have to manage it with the unity ui

snow willow
#

Generally you use prefabs for that

#

and you can assign a sprite image to either a SpriteRenderer or a UI Image component

#

either of which can be parented in code

#

but you cannot parent a Sprite directly, since it's just an image file

agile atlas
#

ok thanks

fast siren
#

so once i collide with the box collider with this code

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class tptolvl2 : MonoBehaviour
{
    void tp(){
        SceneManager.LoadScene("lvl2");
    }
}```
it wont let me go to the scene
#

i also have this so i dont know what is wrong

snow willow
fast siren
#

no