Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Multiplayer-arena-game
/
Multiplayer-arena-game-GameObjects
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7cc65bd5
authored
Feb 02, 2025
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change instantiatedArrow to networkobject
parent
1d5d7af1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
9 deletions
Assets/DefaultNetworkPrefabs.asset
Assets/_Game/Code/Enemy/Enemy.cs
Assets/_Game/Prefabs/Weapons/Arrow.prefab
Assets/_Game/Scenes/SC.unity
Assets/DefaultNetworkPrefabs.asset
View file @
7cc65bd5
...
@@ -39,3 +39,8 @@ MonoBehaviour:
...
@@ -39,3 +39,8 @@ MonoBehaviour:
SourcePrefabToOverride
:
{
fileID
:
0
}
SourcePrefabToOverride
:
{
fileID
:
0
}
SourceHashToOverride
:
0
SourceHashToOverride
:
0
OverridingTargetPrefab
:
{
fileID
:
0
}
OverridingTargetPrefab
:
{
fileID
:
0
}
-
Override
:
0
Prefab
:
{
fileID
:
8885891558877188487
,
guid
:
c0cc14b5c48376d43b0421a2762d35cb
,
type
:
3
}
SourcePrefabToOverride
:
{
fileID
:
0
}
SourceHashToOverride
:
0
OverridingTargetPrefab
:
{
fileID
:
0
}
Assets/_Game/Code/Enemy/Enemy.cs
View file @
7cc65bd5
using
System
;
using
System
;
using
DG.Tweening
;
using
DG.Tweening
;
using
Unity.Netcode
;
using
UnityEngine
;
using
UnityEngine
;
public
class
Enemy
:
MonoBehaviour
public
class
Enemy
:
MonoBehaviour
...
@@ -9,12 +10,12 @@ public class Enemy : MonoBehaviour
...
@@ -9,12 +10,12 @@ public class Enemy : MonoBehaviour
[
SerializeField
]
private
GameObject
weapon
;
[
SerializeField
]
private
GameObject
weapon
;
private
EnemyManager
_enemyManager
;
private
EnemyManager
_enemyManager
;
private
EnemyAnimator
_enemyAnimator
;
private
EnemyAnimator
_enemyAnimator
;
private
Game
Object
_instantiatedArrow
;
private
Network
Object
_instantiatedArrow
;
private
Transform
_arrowSpawnPoint
;
private
Transform
_arrowSpawnPoint
;
private
float
_shootingTimer
;
private
float
_shootingTimer
;
private
bool
_isCrossbowLoaded
;
private
bool
_isCrossbowLoaded
;
private
bool
_isAiming
;
private
bool
_isAiming
;
private
Vector3
_
L
ookingDirection
;
private
Vector3
_
l
ookingDirection
;
private
bool
_targetLocked
;
private
bool
_targetLocked
;
...
@@ -38,7 +39,7 @@ public class Enemy : MonoBehaviour
...
@@ -38,7 +39,7 @@ public class Enemy : MonoBehaviour
{
{
_enemyAnimator
.
InitializeEvents
(
_enemyManager
.
enemyEvents
);
_enemyAnimator
.
InitializeEvents
(
_enemyManager
.
enemyEvents
);
_enemyAnimator
.
receiveTargetShotEventFromAnimator
+=
TargetShotEndEvent
;
_enemyAnimator
.
receiveTargetShotEventFromAnimator
+=
TargetShotEndEvent
;
_enemyAnimator
.
receiveTargetAimedEventFromAnimator
+=
ShootTarget
;
_enemyAnimator
.
receiveTargetAimedEventFromAnimator
+=
ShootTarget
ServerRpc
;
}
}
else
else
{
{
...
@@ -66,12 +67,18 @@ public class Enemy : MonoBehaviour
...
@@ -66,12 +67,18 @@ public class Enemy : MonoBehaviour
throw
new
Exception
(
"ArrowSpawnPoint is not found as a child of Weapon"
);
throw
new
Exception
(
"ArrowSpawnPoint is not found as a child of Weapon"
);
}
}
if
(
NetworkManager
.
Singleton
.
IsListening
)
{
InstantiateArrow
();
InstantiateArrow
();
}
}
else
{
Debug
.
LogError
(
"NetworkManager is not listening, start a server or host before instantiating the arrow"
);
}
}
private
void
InstantiateArrow
()
private
void
InstantiateArrow
()
{
{
_instantiatedArrow
=
Instantiate
(
arrow
,
_arrowSpawnPoint
.
position
,
_arrowSpawnPoint
.
rotation
);
_instantiatedArrow
=
Instantiate
(
arrow
,
_arrowSpawnPoint
.
position
,
_arrowSpawnPoint
.
rotation
)
.
GetComponent
<
NetworkObject
>()
;
_instantiatedArrow
.
transform
.
SetParent
(
weapon
.
transform
);
_instantiatedArrow
.
transform
.
SetParent
(
weapon
.
transform
);
_isCrossbowLoaded
=
true
;
_isCrossbowLoaded
=
true
;
}
}
...
@@ -93,7 +100,6 @@ public class Enemy : MonoBehaviour
...
@@ -93,7 +100,6 @@ public class Enemy : MonoBehaviour
public
void
TargetShotEndEvent
()
public
void
TargetShotEndEvent
()
{
{
Debug
.
Log
(
"Event received"
);
_instantiatedArrow
.
transform
.
SetParent
(
weapon
.
transform
);
_instantiatedArrow
.
transform
.
SetParent
(
weapon
.
transform
);
_instantiatedArrow
.
transform
.
position
=
_arrowSpawnPoint
.
position
;
_instantiatedArrow
.
transform
.
position
=
_arrowSpawnPoint
.
position
;
_instantiatedArrow
.
transform
.
rotation
=
_arrowSpawnPoint
.
rotation
;
_instantiatedArrow
.
transform
.
rotation
=
_arrowSpawnPoint
.
rotation
;
...
@@ -134,18 +140,24 @@ public class Enemy : MonoBehaviour
...
@@ -134,18 +140,24 @@ public class Enemy : MonoBehaviour
private
void
RotateTowardsTarget
(
Collider
hitCollider
)
private
void
RotateTowardsTarget
(
Collider
hitCollider
)
{
{
_enemyManager
.
enemyEvents
.
EnemyAim
();
_enemyManager
.
enemyEvents
.
EnemyAim
();
_
L
ookingDirection
=
(
hitCollider
.
transform
.
position
-
transform
.
position
).
normalized
;
_
l
ookingDirection
=
(
hitCollider
.
transform
.
position
-
transform
.
position
).
normalized
;
Quaternion
lookRotation
=
Quaternion
.
LookRotation
(
new
Vector3
(
_
LookingDirection
.
x
,
0
,
_L
ookingDirection
.
z
));
Quaternion
lookRotation
=
Quaternion
.
LookRotation
(
new
Vector3
(
_
lookingDirection
.
x
,
0
,
_l
ookingDirection
.
z
));
transform
.
DORotateQuaternion
(
lookRotation
,
0.5f
);
transform
.
DORotateQuaternion
(
lookRotation
,
0.5f
);
// .OnComplete(() => { _enemyManager.enemyEvents.EnemyAim(false); });
// .OnComplete(() => { _enemyManager.enemyEvents.EnemyAim(false); });
}
}
[
ServerRpc
]
private
void
ShootTargetServerRpc
()
{
ShootTarget
();
}
private
void
ShootTarget
()
private
void
ShootTarget
()
{
{
_instantiatedArrow
.
transform
.
SetParent
(
null
);
_instantiatedArrow
.
transform
.
SetParent
(
null
);
_instantiatedArrow
.
transform
.
rotation
=
weapon
.
transform
.
rotation
;
_instantiatedArrow
.
transform
.
rotation
=
weapon
.
transform
.
rotation
;
_instantiatedArrow
.
GetComponent
<
Rigidbody
>().
linearVelocity
=
_instantiatedArrow
.
GetComponent
<
Rigidbody
>().
linearVelocity
=
_lookingDirection
*
enemySettings
.
shootingRange
;
_LookingDirection
*
enemySettings
.
shootingRange
;
_shootingTimer
=
enemySettings
.
shootingDelay
;
_shootingTimer
=
enemySettings
.
shootingDelay
;
_isCrossbowLoaded
=
false
;
_isCrossbowLoaded
=
false
;
_enemyManager
.
enemyEvents
.
EnemyAttack
();
_enemyManager
.
enemyEvents
.
EnemyAttack
();
...
...
Assets/_Game/Prefabs/Weapons/Arrow.prefab
View file @
7cc65bd5
...
@@ -12,6 +12,7 @@ GameObject:
...
@@ -12,6 +12,7 @@ GameObject:
-
component
:
{
fileID
:
1165258639717057592
}
-
component
:
{
fileID
:
1165258639717057592
}
-
component
:
{
fileID
:
3689328238253936162
}
-
component
:
{
fileID
:
3689328238253936162
}
-
component
:
{
fileID
:
8067914320767520699
}
-
component
:
{
fileID
:
8067914320767520699
}
-
component
:
{
fileID
:
5623177488314303369
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
Arrow
m_Name
:
Arrow
m_TagString
:
Untagged
m_TagString
:
Untagged
...
@@ -95,6 +96,31 @@ BoxCollider:
...
@@ -95,6 +96,31 @@ BoxCollider:
serializedVersion
:
3
serializedVersion
:
3
m_Size
:
{
x
:
0.1
,
y
:
0.1
,
z
:
0.8
}
m_Size
:
{
x
:
0.1
,
y
:
0.1
,
z
:
0.8
}
m_Center
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_Center
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!114
&5623177488314303369
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
8885891558877188487
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
d5a57f767e5e46a458fc5d3c628d0cbb
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
GlobalObjectIdHash
:
0
InScenePlacedSourceGlobalObjectIdHash
:
0
DeferredDespawnTick
:
0
Ownership
:
1
AlwaysReplicateAsRoot
:
0
SynchronizeTransform
:
1
ActiveSceneSynchronization
:
0
SceneMigrationSynchronization
:
1
SpawnWithObservers
:
1
DontDestroyWithOwner
:
0
AutoObjectParentSync
:
1
SyncOwnerTransformWhenParented
:
1
AllowOwnerToParent
:
0
---
!u!1001
&6279328471144270833
---
!u!1001
&6279328471144270833
PrefabInstance
:
PrefabInstance
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
...
Assets/_Game/Scenes/SC.unity
View file @
7cc65bd5
...
@@ -1608,6 +1608,10 @@ PrefabInstance:
...
@@ -1608,6 +1608,10 @@ PrefabInstance:
propertyPath
:
m_Name
propertyPath
:
m_Name
value
:
Environment
value
:
Environment
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
1342101318069946295
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
m_IsActive
value
:
1
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
2571745861886921497
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
-
target
:
{
fileID
:
2571745861886921497
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
GlobalObjectIdHash
propertyPath
:
GlobalObjectIdHash
value
:
2157953702
value
:
2157953702
...
@@ -1660,10 +1664,22 @@ PrefabInstance:
...
@@ -1660,10 +1664,22 @@ PrefabInstance:
propertyPath
:
GlobalObjectIdHash
propertyPath
:
GlobalObjectIdHash
value
:
1212816001
value
:
1212816001
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
5510887720992502651
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
m_IsActive
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
7270026267180335326
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
-
target
:
{
fileID
:
7270026267180335326
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
GlobalObjectIdHash
propertyPath
:
GlobalObjectIdHash
value
:
745029092
value
:
745029092
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
7466567691796396836
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
m_IsActive
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
7584320928867012029
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
m_IsActive
value
:
1
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
7679692720847302870
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
-
target
:
{
fileID
:
7679692720847302870
,
guid
:
2533a95934a9ea044a5454189730090b
,
type
:
3
}
propertyPath
:
GlobalObjectIdHash
propertyPath
:
GlobalObjectIdHash
value
:
2706695298
value
:
2706695298
...
@@ -1689,6 +1705,10 @@ PrefabInstance:
...
@@ -1689,6 +1705,10 @@ PrefabInstance:
propertyPath
:
m_Name
propertyPath
:
m_Name
value
:
Managers
value
:
Managers
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4994959905079220019
,
guid
:
c3c6003d148e24045a5699c460b258c9
,
type
:
3
}
propertyPath
:
m_IsActive
value
:
1
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6720401888809174077
,
guid
:
c3c6003d148e24045a5699c460b258c9
,
type
:
3
}
-
target
:
{
fileID
:
6720401888809174077
,
guid
:
c3c6003d148e24045a5699c460b258c9
,
type
:
3
}
propertyPath
:
GlobalObjectIdHash
propertyPath
:
GlobalObjectIdHash
value
:
2107378644
value
:
2107378644
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment